In a previous question I wrote about a javascript date function that was mysteriously stopping on 11/07/101. Thanks to the stackoverflow users I was told my problem is Daylight Savings Time. Javascript date, is this my error or did I find a bug?
So my last question on this is what is the recommended approach in Javascript to deal with Daylight Savings Time?
Is http://code.google.com/p/datejs/ the best approach to solve this?
The best way is not to deal with DST. Use the UTC methods and you won’t have to worry about crossing a DST boundary, or any other timezone discontinuity (locale timezone rules can change for more reasons than just DST).
If the above had been done with
new Date(2010, ...)andgetDate()etc, it’d return2010-10-31, the day add failing due to the DST change (in my region, anyway).It is a pity that the ‘default’ most-obvious methods in
Dateare about local time, especially since JavaScript provides so very little context to scripts on what ‘local time’ actually is. UTC is a more stable proposition.