Page 1 of 1

Calculating dates is messing up

Posted: Sun Apr 03, 2011 9:48 pm
by adventuresofgreg
I have a pile of data that is dated using a unix date which is the number of seconds since some UTC date and time in the past. To convert it to a english formated UTC date and time, all I do is convert the date in the past to seconds, then subtract it from the UNIX date and convert the seconds back to date and time. It works as it should EXCEPT, it's excactly ONE hour OFF during daylight savings months. This doesn't make sense to me at all and I can't figure out how to easily correct this without making up some rules about DST (which has changed in the last few years). LC should not be factoring DST into this calculation at all because I'm working with UTC dates and times - yet it does. Is there a way to turn this off?

Greg

Re: Calculating dates is messing up

Posted: Sun Apr 03, 2011 10:32 pm
by bn
Hi Greg,

would the internet date help. It indicates the offset of UTC, the offset takes into account daylight saving time, i.e. for Germany in summer with DST it is UTC + 2 whereas in winter without DST it is UTC + 1.

Or you could set your system settings to Iceland, they are on UTC and don't have DST :)

Kind regards

Bernd

Re: Calculating dates is messing up

Posted: Sun Apr 03, 2011 10:41 pm
by adventuresofgreg
I think the problem is that when I convert a date - like "4/3/2011 15:00:00" to seconds, LC automatically assumes that my date is a local date, and not a UTC date. I require local dates for certain tasks, so changing my system date isn't possible (unless there is a way to 'set' the system date in a LC script, and then set it back when the code is finished executing. - is that possible?

Cheers,
Greg

Re: Calculating dates is messing up

Posted: Sun Apr 03, 2011 11:09 pm
by bn
Hi Greg,

you could correct for DST if you convert your startDate to the internet date first and so on a little like this

Code: Select all

on mouseUp
   put "4/3/2011 01:00:00" into aDate
   put aDate & cr into tOut
   convert aDate to internet date
   put aDate & cr after tOut
   put char 1 of last word of aDate into tSign
   put tSign & cr after tOut
   put (char 2 to - 1 of last word of aDate) into tOffset
   replace "0" with "" in tOffset
   put tOffset & cr after tOut
   convert aDate to dateItems
   put aDate & cr after tOut
   subtract (tSign & tOffset) from item 4 of aDate
   put aDate & cr after tOut
   convert aDate to dateItems
   put aDate & cr after tOut
   convert aDate to internet date
   put aDate & cr after tOut
   put tOut
end mouseUp
put this into a button and it will put the read out into the message box. Adjust for a time in your time zone where the offset of UTC with/without will change the date and see what happens.

Kind regards

Bernd

'set' the system date in a LC script, and then set it back when the code is finished executing. - is that possible?
not natively from within Livecode.

Kind regards

Bernd