diff options
author | Muh Muhten <muh.muhten@gmail.com> | 2019-01-30 00:41:47 -0500 |
---|---|---|
committer | Nico Williams <nico@cryptonector.com> | 2019-01-30 22:05:51 -0600 |
commit | 3c5b1419a278dfb192666b33197dc182c670290d (patch) | |
tree | d4d039133ff41e692f829ce9a07b1557c0ab2aa2 | |
parent | 012af2186bb202edea4781a8128001bb078bbb27 (diff) |
Unify timegm fallbacks into my_mktime
my_timegm was introduced in 1900c7 to add a mktime fallback used in
4a6241, the subsequently removed in c53823. As a result of this code
shuffling, the jq mktime function (f_mktime) wound up using a fallback
even on systems where timegm is available, with incorrect results in
some time zones with DST, e.g.
% TZ=America/New_York jq -n '"2018-08-31T00:00:00Z"|fromdate|todate'
"2018-08-31T01:00:00Z"
This undoes 1900c7 and moves the workaround it added into the #else of
my_mktime.
-rw-r--r-- | src/builtin.c | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/builtin.c b/src/builtin.c index 48dec451..baa68915 100644 --- a/src/builtin.c +++ b/src/builtin.c @@ -1225,10 +1225,21 @@ static int setenv(const char *var, const char *val, int ovr) * * Returns (time_t)-2 if mktime()'s side-effects cannot be corrected. */ -static time_t my_timegm(struct tm *tm) { +static time_t my_mktime(struct tm *tm) { #ifdef HAVE_TIMEGM return timegm(tm); -#else /* HAVE_TIMEGM */ +#elif HAVE_TM_TM_GMT_OFF + + time_t t = mktime(tm); + if (t == (time_t)-1) + return t; + return t + tm->tm_gmtoff; +#elif HAVE_TM___TM_GMT_OFF + time_t t = mktime(tm); + if (t == (time_t)-1) + return t; + return t + tm->__tm_gmtoff; +#else char *tz; tz = (tz = getenv("TZ")) != NULL ? strdup(tz) : NULL; @@ -1238,18 +1249,6 @@ static time_t my_timegm(struct tm *tm) { if (tz != NULL) setenv("TZ", tz, 1); return t; -#endif /* !HAVE_TIMEGM */ -} -static time_t my_mktime(struct tm *tm) { - time_t t = mktime(tm); - if (t == (time_t)-1) - return t; -#ifdef HAVE_TM_TM_GMT_OFF - return t + tm->tm_gmtoff; -#elif HAVE_TM___TM_GMT_OFF - return t + tm->__tm_gmtoff; -#else - return (time_t)-2; /* Not supported */ #endif } |