From 9b94ea9bd1a7cc392193e78c137bde5bc415375b Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Sun, 22 Jun 2014 10:41:51 -0700 Subject: [PATCH] interpret times in UTC, not local timezone --- libarchive/archive_read_support_format_warc.c | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) 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) { -- 2.47.2