Results 1 to 4 of 4

Thread: Is this a Daylight Saving Time Bug?

  1. #1
    Join Date
    Dec 2006

    Is this a Daylight Saving Time Bug?

    I'm trying to determine if this is a bug or not. Here in the northeast of the United States, we observe Daylight Saving Time which this year started on April 2 at 2:00am. If you create a Javascript date for say, 04/02/2006 02:30, Javascript changes it to 04/02/2006 01:30!

    Now a case could be made that the magic hour between 2:00am and 3:00am on this date doesn't really exist so the creators of Javascript had to pick a date and time but why would they back up an hour? Wouldn't it make more sense to "spring forward" an hour and make it 04/02/2006 03:30? Here is a bit of code to prove it. I am curious to see if others in other time zones and using other operating systems and browsers see the same results.
    PHP Code:
    // Pad with zeros
    function PZ(v){return(v<0||v>9?"":"0")+v}
    // Test DST.
    function testDSTdate()
    newdate = new Date(2006,03,02,02,30);
    strdate newdate.getFullYear() + "/" PZ(newdate.getMonth()+1) + "/" PZ(newdate.getDate()) + " " PZ(newdate.getHours()) + ":" PZ(newdate.getMinutes());

    Last edited by geolev; 12-08-2006 at 12:47 PM.

  2. #2
    Join Date
    Nov 2006
    OK, I'll try to explain this.

    First of all it is not a Javascript issue. Javascript is only displaying the time it gets from the OS. If you turn off the option for Windows to observer daylight savings time you will not see this anomoly.

    Second, it is not a bug. Right now we are on standard time and the issue you describe only exists for that 1 hour period on the spring change for previous years. The fall time change and future spring changes do not react the same.

    Now the difficult part of explaining why it is correct. At 2AM (daylight time) the time jumped to 3AM (standard time). So, looking back from today - using standard time - 3AM was 3AM. But, what was it 1 minute prior to that (2:59AM)? There was no 2:59AM because we skipped over it - so we skip over it, going in reverse this time, and get 1:59AM.

  3. #3
    Join Date
    Dec 2006
    Okay. I'm reading alot into what you said so let me see if I understand.

    When I created a date, var newdate = new Date(2006,03,02,02,30);, are you saying that Javascript is actually requesting this date from the OS?

    If that is true, then it makes sense what is happening is that the OS is actually returning the number of milliseconds between the date I specified and the epoch. This is what the Javascript date actually contains right? And, because I have the "observes daylight saving time" option set, the OS is subtracting an hours worth of milliseconds from the result to account for the hour that was skipped.

    Do I have it right?


  4. #4
    Join Date
    Feb 2006
    And if you set the date to the 31st of November (new Date(2006,10,31))
    you get Dec 1...would you say it is a bug that a nonexistent day or time is
    not returned?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center