Merge branch 'jc/epochtime-wo-tz' into maint-2.3

"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
This commit is contained in:
Junio C Hamano 2015-05-11 14:33:58 -07:00
Родитель 16018ae5fb f6e6362107
Коммит 13ec221d8c
1 изменённых файлов: 9 добавлений и 5 удалений

14
date.c
Просмотреть файл

@ -704,10 +704,17 @@ int parse_date_basic(const char *date, unsigned long *timestamp, int *offset)
date += match; date += match;
} }
/* mktime uses local timezone */ /* do not use mktime(), which uses local timezone, here */
*timestamp = tm_to_time_t(&tm); *timestamp = tm_to_time_t(&tm);
if (*timestamp == -1)
return -1;
if (*offset == -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) { if ((time_t)*timestamp > temp_time) {
*offset = ((time_t)*timestamp - temp_time) / 60; *offset = ((time_t)*timestamp - temp_time) / 60;
} else { } else {
@ -715,9 +722,6 @@ int parse_date_basic(const char *date, unsigned long *timestamp, int *offset)
} }
} }
if (*timestamp == -1)
return -1;
if (!tm_gmt) if (!tm_gmt)
*timestamp -= *offset * 60; *timestamp -= *offset * 60;
return 0; /* success */ return 0; /* success */