Timestamps are irreversible

Report any Hollywood bugs here
Post Reply
User avatar
lazi
Posts: 625
Joined: Thu Feb 24, 2011 11:08 pm

Timestamps are irreversible

Post 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.
plouf
Posts: 470
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Timestamps are irreversible

Post by plouf »

i think they are 54 secs diffirence

exactly as timestamp diffirence
Christos
User avatar
airsoftsoftwair
Posts: 5443
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Timestamps are irreversible

Post 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.
plouf
Posts: 470
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Timestamps are irreversible

Post 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
Christos
User avatar
lazi
Posts: 625
Joined: Thu Feb 24, 2011 11:08 pm

Re: Timestamps are irreversible

Post 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!
User avatar
airsoftsoftwair
Posts: 5443
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Timestamps are irreversible

Post 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
Post Reply