From: Jonas Fonseca Date: Wed, 4 Feb 2009 16:10:04 +0000 (+0100) Subject: Refactor and unify timezone parsing X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=60c440586f21704fcfec49d5c4dcfb8b840c737f;p=tig.git Refactor and unify timezone parsing --- diff --git a/tig.c b/tig.c index 6d0983c..e0d0640 100644 --- a/tig.c +++ b/tig.c @@ -3308,6 +3308,22 @@ view_driver(struct view *view, enum request request) * View backend utilities */ +static void +parse_timezone(time_t *time, const char *zone) +{ + long tz; + + tz = ('0' - zone[1]) * 60 * 60 * 10; + tz += ('0' - zone[2]) * 60 * 60; + tz += ('0' - zone[3]) * 60; + tz += ('0' - zone[4]); + + if (zone[0] == '-') + tz = -tz; + + *time -= tz; +} + /* Parse author lines where the name may be empty: * author 1138474660 +0100 */ @@ -3335,20 +3351,8 @@ parse_author_line(char *ident, char *author, size_t authorsize, struct tm *tm) char *zone = strchr(secs, ' '); time_t time = (time_t) atol(secs); - if (zone && strlen(zone) == STRING_SIZE(" +0700")) { - long tz; - - zone++; - tz = ('0' - zone[1]) * 60 * 60 * 10; - tz += ('0' - zone[2]) * 60 * 60; - tz += ('0' - zone[3]) * 60; - tz += ('0' - zone[4]) * 60; - - if (zone[0] == '-') - tz = -tz; - - time -= tz; - } + if (zone && strlen(zone) == STRING_SIZE(" +0700")) + parse_timezone(&time, zone + 1); gmtime_r(&time, tm); } @@ -4337,17 +4341,7 @@ blame_read(struct view *view, char *line) author_time = (time_t) atol(line); } else if (match_blame_header("author-tz ", &line)) { - long tz; - - tz = ('0' - line[1]) * 60 * 60 * 10; - tz += ('0' - line[2]) * 60 * 60; - tz += ('0' - line[3]) * 60; - tz += ('0' - line[4]) * 60; - - if (line[0] == '-') - tz = -tz; - - author_time -= tz; + parse_timezone(&author_time, line); gmtime_r(&author_time, &commit->time); } else if (match_blame_header("summary ", &line)) {