diff options
author | Tim Kientzle <kientzle@acm.org> | 2014-06-22 10:41:51 -0700 |
---|---|---|
committer | Tim Kientzle <kientzle@acm.org> | 2014-06-22 10:41:51 -0700 |
commit | 9b94ea9bd1a7cc392193e78c137bde5bc415375b (patch) | |
tree | f0b6f0487fbdaa87a6ec17586b230e38004e234c /libarchive/archive_read_support_format_warc.c | |
parent | 0128b5ac0833150c4ed870bd4419cb8b71501964 (diff) | |
download | libarchive-9b94ea9bd1a7cc392193e78c137bde5bc415375b.tar.gz |
interpret times in UTC, not local timezone
Diffstat (limited to 'libarchive/archive_read_support_format_warc.c')
-rw-r--r-- | libarchive/archive_read_support_format_warc.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/libarchive/archive_read_support_format_warc.c b/libarchive/archive_read_support_format_warc.c index 9f06f0c2..aa5045a3 100644 --- a/libarchive/archive_read_support_format_warc.c +++ b/libarchive/archive_read_support_format_warc.c @@ -496,6 +496,28 @@ strtoi_lim(const char *str, const char **ep, int llim, int ulim) } 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) { /** like strptime() but strictly for ISO 8601 Zulu strings */ @@ -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) { |