Skip to content

Commit 9b94ea9

Browse files
committed
interpret times in UTC, not local timezone
1 parent 0128b5a commit 9b94ea9

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

libarchive/archive_read_support_format_warc.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,28 @@ strtoi_lim(const char *str, const char **ep, int llim, int ulim)
495495
return res;
496496
}
497497

498+
static time_t
499+
time_from_tm(struct tm *t)
500+
{
501+
#if HAVE_TIMEGM
502+
/* Use platform timegm() if available. */
503+
return (timegm(t));
504+
#elif HAVE__MKGMTIME64
505+
return (_mkgmtime64(t));
506+
#else
507+
/* Else use direct calculation using POSIX assumptions. */
508+
/* First, fix up tm_yday based on the year/month/day. */
509+
if (mktime(t) == (time_t)-1)
510+
return ((time_t)-1);
511+
/* Then we can compute timegm() from first principles. */
512+
return (t->tm_sec + t->tm_min * 60 + t->tm_hour * 3600
513+
+ t->tm_yday * 86400 + (t->tm_year - 70) * 31536000
514+
+ ((t->tm_year - 69) / 4) * 86400 -
515+
((t->tm_year - 1) / 100) * 86400
516+
+ ((t->tm_year + 299) / 400) * 86400);
517+
#endif
518+
}
519+
498520
static time_t
499521
xstrpisotime(const char *s, char **endptr)
500522
{
@@ -538,8 +560,8 @@ xstrpisotime(const char *s, char **endptr)
538560
tm.tm_year -= 1900;
539561
tm.tm_mon--;
540562

541-
/* now convert our custom tm struct to a unix stamp */
542-
res = mktime(&tm);
563+
/* now convert our custom tm struct to a unix stamp using UTC */
564+
res = time_from_tm(&tm);
543565

544566
out:
545567
if (endptr != NULL) {

0 commit comments

Comments
 (0)