From: Tim Kientzle Date: Sun, 22 Jun 2014 17:41:51 +0000 (-0700) Subject: interpret times in UTC, not local timezone X-Git-Tag: v3.1.900a~283 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9b94ea9bd1a7cc392193e78c137bde5bc415375b;p=thirdparty%2Flibarchive.git interpret times in UTC, not local timezone --- diff --git a/libarchive/archive_read_support_format_warc.c b/libarchive/archive_read_support_format_warc.c index 9f06f0c2c..aa5045a36 100644 --- a/libarchive/archive_read_support_format_warc.c +++ b/libarchive/archive_read_support_format_warc.c @@ -495,6 +495,28 @@ strtoi_lim(const char *str, const char **ep, int llim, int ulim) return res; } +static time_t +time_from_tm(struct tm *t) +{ +#if HAVE_TIMEGM + /* Use platform timegm() if available. */ + return (timegm(t)); +#elif HAVE__MKGMTIME64 + return (_mkgmtime64(t)); +#else + /* Else use direct calculation using POSIX assumptions. */ + /* First, fix up tm_yday based on the year/month/day. */ + if (mktime(t) == (time_t)-1) + return ((time_t)-1); + /* Then we can compute timegm() from first principles. */ + return (t->tm_sec + t->tm_min * 60 + t->tm_hour * 3600 + + t->tm_yday * 86400 + (t->tm_year - 70) * 31536000 + + ((t->tm_year - 69) / 4) * 86400 - + ((t->tm_year - 1) / 100) * 86400 + + ((t->tm_year + 299) / 400) * 86400); +#endif +} + static time_t xstrpisotime(const char *s, char **endptr) { @@ -538,8 +560,8 @@ xstrpisotime(const char *s, char **endptr) tm.tm_year -= 1900; tm.tm_mon--; - /* now convert our custom tm struct to a unix stamp */ - res = mktime(&tm); + /* now convert our custom tm struct to a unix stamp using UTC */ + res = time_from_tm(&tm); out: if (endptr != NULL) {