|
Haravikk Mistral
Registered User
Join date: 8 Oct 2005
Posts: 2,482
|
07-30-2006 15:46
Okay, this is for a simple script that is turning out not to be so simple!
Basically what I want to do is calculate whether or not it is currently daylight savings time in europe (+1 hour between the last Sunday of March and the last Sunday of October at 1am each time). However, my script will be dealing with time fairly frequently so I don't want to check every time. Ideally what I'd like to do is calculate when the next change will occur and whether it is daylight savings at the moment. This way when the change-time is reached we simple flip a variable 'dayLightSavings' from TRUE to FALSE or vice versa as appropriate. e.g, it is 15th June 2006, 13:06pm, time will change on the last Sunday of October at 1am. How many seconds will it be until this time is reached? Since October (the end of DST) is the next event, then we are currently on DST, so set that flag to true.
My big issue is not the scripting, my main issue is that I am dreadful with dates and am getting myself really lost in this.
Is there a script out there that can do this already or anyone who's more familiar with the problem than I am? It seems to involve all possible time-related problems such as days of week, handling dates and calculating time.
Anyway able to give any help on this one?
_____________________
Computer (Mac Pro): 2 x Quad Core 3.2ghz Xeon 10gb DDR2 800mhz FB-DIMMS 4 x 750gb, 32mb cache hard-drives (RAID-0/striped) NVidia GeForce 8800GT (512mb)
|
|
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
|
07-31-2006 00:03
Convert them to unix time and take away? There must be an algorithm out there that does that easily (google might help). If not there's an algorithm for the conversion the other way in lsl somewhere, you could reverse engineer that maybe?
|
|
Bitzer Balderdash
Dazed and Confused
Join date: 21 Dec 2005
Posts: 246
|
07-31-2006 01:20
Two possibilities, both basically cheats
first off, you can check very easily if Pacific Time is on PST/PDT by comparing llGetWallClock and llGetGMTClock, and seeing if there is 7 or 8 hours between them, but I couldn't tell you for sure whether PST/PDT shifts at the same weekend as European time does.
Second option is to pre-calculate the unix timestamp values at which the shifts are due to happen for the next decade or so - two a year, not exactly a lot of memory. Stick them into a notecaed (for east of updates and future-proofing), and just check when the next one of them is due by subtracting llGetUnixTime from it.
|
|
Freyr Elvehjem
Registered User
Join date: 13 May 2006
Posts: 133
|
07-31-2006 04:33
Here are the equations for the US (but check me on them). For this year, calculate the end of DST with October [31 - (floor(year * 5/4 + 1) mod 7)] As of next year the new DST law goes into effect (DST will be about a month longer). For 2007 and beyond, in the US, DST begins on March [14 - (floor(year * 5/4 + 1) mod 7)] and ends on November [7 - (floor(year * 5/4 + 1) mod 7)] The date should always fall on a Sunday and the time changes at 2:00 in the morning(even under the new law).
|
|
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
|
07-31-2006 05:13
From: Bitzer Balderdash Two possibilities, both basically cheats
first off, you can check very easily if Pacific Time is on PST/PDT by comparing llGetWallClock and llGetGMTClock, and seeing if there is 7 or 8 hours between them, but I couldn't tell you for sure whether PST/PDT shifts at the same weekend as European time does.
Second option is to pre-calculate the unix timestamp values at which the shifts are due to happen for the next decade or so - two a year, not exactly a lot of memory. Stick them into a notecaed (for east of updates and future-proofing), and just check when the next one of them is due by subtracting llGetUnixTime from it. Current we go forward a week earlier than the US, and back at the same time. Australia and NZ usually change on the same weekends as Europe, but in the opposite directions. I'm not sure what the new laws will do. Will states that don't have DST also have to change now?
|
|
Freyr Elvehjem
Registered User
Join date: 13 May 2006
Posts: 133
|
07-31-2006 05:28
From: Eloise Pasteur I'm not sure what the new laws will do. Will states that don't have DST also have to change now? I do not think the new federal law will force places that aren't currently using DST to start using it. I'm not 100% certain of that, but IIRC Alaska is still working to pass a law to stop using DST...I doubt they'd be doing that if the state law wouldn't matter next year anyway. Right now the only two states that don't use DST are Arizona (though I think Native American reservations decide independently) and Hawaii. Indiana used to not use use DST in most counties but now every county in that state uses DST as of this year.
|