[Sbcl-help] Getting weird timezone values by decoding small universal-time values

1 view
Skip to first unread message

tech...@zacque.tk

unread,
Apr 24, 2023, 11:59:26 PM4/24/23
to sbcl...@lists.sourceforge.net
Hi,

I got the weird timezone value of -331/45 by evaluating
(DECODE-UNIVERSAL-TIME 3742); timezone value of -15/2 with
(DECODE-UNIVERSAL-TIME 900000000).

Is this an expected behaviour? I'll expect it to return -8 (which is my
time-zone) for every positive integer. For reference, (GET-DECODED-TIME)
works perfectly fine (i.e. returning correct date, time, and timezone):

CL-USER> (get-decoded-time)
39
28
11
25
4
2023
1
NIL
-8

After debugging it a little bit, DECODE-UNIVERSAL-TIME seems to return:
-331/45 for every integer in the range [0,825525519] (inclusive),
-15/2 for [825525520, 1041352199], and
-8 for [1041352200, positive infinity?).

My debugging code:
(defun ut-time-zone (int)
(multiple-value-bind (s m h d month y day daylight zone)
(decode-universal-time int)
(declare (ignore s m h d month y day daylight))
zone))

(defun half-int (a b)
(truncate (/ (+ a b) 2)))

(defun time-zone-not-x (lower upper timezone)
(loop for x = (half-int lower upper)
if (= (ut-time-zone x) timezone)
do (setf upper x)
else
do (setf lower x)
until (and (/= (ut-time-zone x) timezone)
(= (ut-time-zone (1+ x)) timezone))
finally (return x)))

At the REPL:

CL-USER> (time-zone-not-x 3742 900000000 -15/2)
825525519
CL-USER> (time-zone-not-x 900000000 1500000000 -8)
1041352199


My machine and environment: x86_64, Xubuntu 20.04.3 LTS (Linux 5.15
kernel), SBCL 2.2.10.


From:
Jiahong


_______________________________________________
Sbcl-help mailing list
Sbcl...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sbcl-help

Richard M Kreuter

unread,
Apr 25, 2023, 10:15:48 PM4/25/23
to tech...@zacque.tk, sbcl...@lists.sourceforge.net
Hi Jiahong,

I believe DECODE-UNIVERSAL-TIME uses the zoneinfo database [1] for
localizing time values. The zoneinfo database has an entry that would
match your description:

# Sabah & Sarawak
# From Paul Eggert (2014-08-12):
# The data entries here are mostly from Shanks & Pottenger, but the 1942, 1945
# and 1982 transition dates are from Mok Ly Yng.
# Zone NAME STDOFF RULES FORMAT [UNTIL]
Zone Asia/Kuching 7:21:20 - LMT 1926 Mar
7:30 - +0730 1933
8:00 NBorneo +08/+0820 1942 Feb 16
9:00 - +09 1945 Sep 12
8:00 - +08

7 hours, 21 minutes, and 20 seconds is 331/45 hours; and the universal
time you found as the upper bound for that unusual offset, 825525519,
is, I think, 7h21m20s before 1 March 1926 00:00:00 GMT.

So does something like "Asia/Kuching" resemble your host's timezone
setting?

Regards,
Richard

[1] https://www.iana.org/time-zones

Technical Zacque

unread,
Apr 26, 2023, 7:33:10 AM4/26/23
to Richard M Kreuter, sbcl...@lists.sourceforge.net
Hi Richard,

> I believe DECODE-UNIVERSAL-TIME uses the zoneinfo database [1] for
> localizing time values.

I see, thought there was a bug in SBCL’s DECODE-UNIVERSAL-TIME. Didn’t realise there is a zoneinfo database used for this info, and that timezone info even changes over time.

> So does something like "Asia/Kuching" resemble your host's timezone
> setting?

Exactly! That was an impressive analysis! Glad to learn something new today. :)

Thanks,

Reply all
Reply to author
Forward
0 new messages