links icon indicating copy to clipboard operation
links copied to clipboard

dateToInt -> intToDate does not roundtrip depending on time zone

Open darrenldl opened this issue 1 year ago • 3 comments

Hello,

Context

I am the main developer of Timedesc - a modern alternative to calendar essentially, and I was poking around at packages which depend on calendar out of curiosity to see if it causes issue in other packages (there have been known issues in ISO8601.ml etc).

(Interesting language! I like the language design quite a lot.)

Problem

For time zones outside of UTC, conversion from date time to timestamp and back yields a different date time.

Europe/London

$ TZ=Europe/London linx
 _     _ __   _ _  __  ___
/ |   | |  \ | | |/ / / ._\
| |   | | , \| |   /  \  \
| |___| | |\ \ | |\ \ _\  \
|_____|_|_| \__|_| \_|____/
Welcome to Links version 0.9.7 (Burghmuirhead)
links> var t1 = parseDate("2022-05-20 15:00:00+0");
t1 = 2022-05-20 16:00:00.000000+1 : DateTime
links> var t2 = dateToInt(t1);
t2 = 1653055200 : Int
links> var t3 = intToDate(t2);
t3 = 2022-05-20 15:00:00.000000+1 : DateTime
links> var t4 = dateToInt(t3);
t4 = 1653051600 : Int

Australia/Sydney

$ TZ=Australia/Sydney linx
 _     _ __   _ _  __  ___
/ |   | |  \ | | |/ / / ._\
| |   | | , \| |   /  \  \
| |___| | |\ \ | |\ \ _\  \
|_____|_|_| \__|_| \_|____/
Welcome to Links version 0.9.7 (Burghmuirhead)
links> var t1 = parseDate("2022-05-20 15:00:00+0");
t1 = 2022-05-21 01:00:00.000000+10 : DateTime
links> var t2 = dateToInt(t1);
t2 = 1653022800 : Int
links> var t3 = intToDate(t2);
t3 = 2022-05-20 15:00:00.000000+10 : DateTime
links> var t4 = dateToInt(t3);
t4 = 1652986800 : Int

UTC (this is fine)

$ TZ=UTC linx
 _     _ __   _ _  __  ___
/ |   | |  \ | | |/ / / ._\
| |   | | , \| |   /  \  \
| |___| | |\ \ | |\ \ _\  \
|_____|_|_| \__|_| \_|____/
Welcome to Links version 0.9.7 (Burghmuirhead)
links> var t1 = parseDate("2022-05-20 15:00:00+0");
t1 = 2022-05-20 15:00:00.000000+0 : DateTime
links> var t2 = dateToInt(t1);
t2 = 1653058800 : Int
links> var t3 = intToDate(t2);
t3 = 2022-05-20 15:00:00.000000+0 : DateTime
links> var t4 = dateToInt(t3);
t4 = 1653058800 : Int

I will say I don't know if I'm using links correctly, or how relevant this might be to links, or how the interaction with DB works etc.

darrenldl avatar Aug 08 '22 06:08 darrenldl

Thanks! This looks like an issue for @SimonJF -- I'll let you have a look first.

dhil avatar Aug 08 '22 14:08 dhil

I believe @SimonJF is away for a bit. It's totally plausible to me that we might not be doing the right thing here, especially since this may have been tested in a time/place where GMT/UTC would have been the default. Probably we should also be providing a variant of intToDate that takes an explicit timezone.

jamescheney avatar Aug 08 '22 14:08 jamescheney

Thanks, will take a look when I’m back! I think @jamescheney is likely right in that we are probably relying on an underlying UK time assumption for intToDate. Wonder what happens on the client, too.

SimonJF avatar Aug 08 '22 14:08 SimonJF