diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2023-11-19 23:30:02 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2023-11-19 23:30:02 -0800 |
commit | 3155f9903ec263d33f375c762a6a346bc8dc92c5 (patch) | |
tree | d2fbec03a7df87436db24fe974887500b3ea22a8 /time.c | |
parent | ad068f27d819465c78c574019f32a2e1d30ca5ff (diff) | |
download | txr-3155f9903ec263d33f375c762a6a346bc8dc92c5.tar.gz txr-3155f9903ec263d33f375c762a6a346bc8dc92c5.tar.bz2 txr-3155f9903ec263d33f375c762a6a346bc8dc92c5.zip |
time: bug: must subtract gmtoff, not add.
This works fine:
1> (time-struct-utc 0)
#S(time year 1970 month 1 day 1 hour 0 min 0 sec 0 wday 4 yday 0
dst nil gmtoff 0 zone "GMT")
2> *1.(time-utc)
0
3> *1.(time-local)
28800
But we want the following to return the same results:
1> (time-struct-local 0)
#S(time year 1969 month 12 day 31 hour 16 min 0 sec 0 wday 3 yday 364
dst nil gmtoff -28800 zone "PST")
2> *1.(time-utc)
-57600
3> *1.(time-local)
-28800
With the patch, we do:
1> (time-struct-local 0)
#S(time year 1969 month 12 day 31 hour 16 min 0 sec 0 wday 3 yday 364
dst nil gmtoff -28800 zone "PST")
2> *1.(time-utc)
0
3> *1.(time-local)
28800
This is also broken:
1> (time-parse-utc "%H:%M:%z" "00:00:-0800")
-28800
It must return 28800.
* time.c (time_meth): This function, which is the
imlpementation of the time-utc and time-local methods, must
subtract the gmtoff field, not add it. This is so that
a UTC time expressed in a local time zone will convert
back to the correct UTC epoch.
(time_parse_local, time_parse_utc): Here we likewise
must subtract the gmtoff.
Diffstat (limited to 'time.c')
-rw-r--r-- | time.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -438,7 +438,7 @@ static val time_meth(val utc_p, val time_struct) hour, min, sec, dst); if (gmtoff) - out = plus(out, gmtoff); + out = minus(out, gmtoff); return out; } @@ -501,7 +501,7 @@ val time_parse_local(val format, val string) #if HAVE_TM_GMTOFF { long gmtoff = tms.TM_GMTOFF; - return num(mktime(&tms) + gmtoff); + return num(mktime(&tms) - gmtoff); } #else return num(mktime(&tms)); @@ -516,12 +516,12 @@ val time_parse_utc(val format, val string) #if HAVE_TIMEGM && HAVE_TM_GMTOFF { long gmtoff = tms.TM_GMTOFF; - return num_time(timegm(&tms) + gmtoff); + return num_time(timegm(&tms) - gmtoff); } #elif HAVE_TM_GMTOFF { long gmtoff = tms.TM_GMTOFF; - return num_time(timegm_hack(&tms) + tms.gmtoff); + return num_time(timegm_hack(&tms) - tms.gmtoff); } #elif HAVE_TIMEGM return num_time(timegm(&tms)); |