Skip to content

Commit

Permalink
Merge branch 'jc/epochtime-wo-tz' into maint-2.3
Browse files Browse the repository at this point in the history
"git commit --date=now" or anything that relies on approxidate lost
the daylight-saving-time offset.

* jc/epochtime-wo-tz:
  parse_date_basic(): let the system handle DST conversion
  parse_date_basic(): return early when given a bogus timestamp
  • Loading branch information
Junio C Hamano committed May 11, 2015
2 parents 16018ae + f6e6362 commit 13ec221
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions date.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,20 +704,24 @@ int parse_date_basic(const char *date, unsigned long *timestamp, int *offset)
date += match;
}

/* mktime uses local timezone */
/* do not use mktime(), which uses local timezone, here */
*timestamp = tm_to_time_t(&tm);
if (*timestamp == -1)
return -1;

if (*offset == -1) {
time_t temp_time = mktime(&tm);
time_t temp_time;

/* gmtime_r() in match_digit() may have clobbered it */
tm.tm_isdst = -1;
temp_time = mktime(&tm);
if ((time_t)*timestamp > temp_time) {
*offset = ((time_t)*timestamp - temp_time) / 60;
} else {
*offset = -(int)((temp_time - (time_t)*timestamp) / 60);
}
}

if (*timestamp == -1)
return -1;

if (!tm_gmt)
*timestamp -= *offset * 60;
return 0; /* success */
Expand Down

0 comments on commit 13ec221

Please sign in to comment.