Page 1 of 1

Timestamps are irreversible

Posted: Thu Jun 18, 2020 9:47 pm
by lazi
I think dates can be easier to handle and store as timestamps.
There is the two functions that can convert back and forth timestamps and dates, but they not works enough precisely.

Code: Select all

x=DateToTimestamp("12-Jan-2020 00:00:05")

DebugPrint(x)
DebugPrint(TimestampToDate(x,True))  
The results on OS4 is:
1578783551
11-Jan-2020 22:59:11
One hour differency could be blamed for DST, but what is that 54 seconds?

Windows result is different:
1578783605
11-Jan-2020 23:00:05
That looks like exactly one hour differency, however not good to store the date.

Re: Timestamps are irreversible

Posted: Thu Jun 18, 2020 11:12 pm
by plouf
i think they are 54 secs diffirence

exactly as timestamp diffirence

Re: Timestamps are irreversible

Posted: Sat Jun 20, 2020 2:45 pm
by airsoftsoftwair
The result on Windows is correct. The one hour difference is because DateToTimestamp() will convert local time to UTC time so on systems on which January 2020 is in timezone UTC+1 (as it is the case in Hungary I guess) you'll get 11-Jan-2020 23:00:05.

On OS4 the result is obviously wrong. Probably a bug in OS4's clib2 as it works correctly on MorphOS and on OS3. I'll check and fix it.

Re: Timestamps are irreversible

Posted: Sun Jun 21, 2020 7:15 am
by plouf
o kthe hour based on original shoube be GMT not dst

here i get
1578780005
11-Jan-2020 22:00:05

where i am at +2 (+1 due to dst today i am at +3), but i get -2 which is diffirence of GMT of Greece

Re: Timestamps are irreversible

Posted: Thu Jun 25, 2020 10:00 am
by lazi
So sum it up:

To timestamp:

Code: Select all

ts = DateToTimestamp ( dt )
Back to local time:

Code: Select all

dt = UTCToDate ( TimestampToDate ( ts, True )
Thanks!

Re: Timestamps are irreversible

Posted: Wed Jul 01, 2020 4:15 pm
by airsoftsoftwair
Congratulations for discovering this! One of the basic C runtime functions in clib2 was broken for almost 20 years and nobody noticed it. Now it's finally fixed!

Code: Select all

- Fix [OS4]: DateToTimestamp() and DateToUTC() didn't work correctly because of a bug in AmigaOS4's clib2