Daylight Saving Time
Adding Methods to the Date Object
What we are going to do is to select two dates - the first of January and the first of July. In those places where daylight saving time is used we are going to assume that daylight saving time is not in force on one of these two dates. Provided that this assumption is correct for everywhere that uses daylight saving time then the following methods will function correctly. If there is anywhere in the world that applies daylight saving time on both of those dates then our code will fail.
var jan = new Date(this.getFullYear(), 0, 1);
var jul = new Date(this.getFullYear(), 6, 1);
return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
Provided that one of those two dates is not on daylight savings time that method will return the timezone from that date (since a day that is on daylight saving time will have an offset that is one greater since the clocks are moved forward when daylight saving applies eg Sydney standard timezone is 10 and DST is 11, New York standard timezone is -5 and DST is -4).
Now that we have a way to obtain the standard time timezone offset we have a relatively simple way of determining if the current time is on daylight saving time or not. We simply compare the current timezone offset with the standard one. If they are equal then the current time is standard time. If they are not then the current time is daylight saving time.
return this.getTimezoneOffset() < this.stdTimezoneOffset();
What about those places that don't use daylight saving time? Well our methods already handle that too. Where that is the case the two timezone offsets the first method looks at will be the same and therefore the minimum of the two will still give us the standard timezone offset. Since the offset throughout the year will always be that same value our second method will therefore always return false.
So let's end with a working example of the script in action. The following paragraph will update automatically so as to be correct for the timezone you have your computer set to. It does it simply by creating a date object set to today's date (var today = new Date();) and then tests if we need to remove the word "not" from the sentence (if (today.dst()) ...).
Where you are is currently not on daylight saving.