Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript Date objects and Daylight Savings Time
    primarykey
    data
    text
    <p>I'm seeing some behavior I don't understand with Javascript date objects and DST transitions. If I execute the following in Chrome's javascript console</p> <pre><code>var date = new Date(1268535600000); //2010-03-14T03:00:00.000Z (21:00 03-13 America/Chicago) for(var i = 1; i &lt;= 12; i++) { var time = date.getHours(); console.log(time) console.log(date) date.setHours(date.getHours() + 1); } </code></pre> <p>the output is:</p> <pre><code>21 Sat Mar 13 2010 21:00:00 GMT-0600 (Central Standard Time) 22 Sat Mar 13 2010 22:00:00 GMT-0600 (Central Standard Time) 23 Sat Mar 13 2010 23:00:00 GMT-0600 (Central Standard Time) 0 Sun Mar 14 2010 00:00:00 GMT-0600 (Central Standard Time) 1 Sun Mar 14 2010 01:00:00 GMT-0600 (Central Standard Time) 1 Sun Mar 14 2010 01:00:00 GMT-0600 (Central Standard Time) 1 Sun Mar 14 2010 01:00:00 GMT-0600 (Central Standard Time) 1 Sun Mar 14 2010 01:00:00 GMT-0600 (Central Standard Time) 1 Sun Mar 14 2010 01:00:00 GMT-0600 (Central Standard Time) 1 Sun Mar 14 2010 01:00:00 GMT-0600 (Central Standard Time) 1 Sun Mar 14 2010 01:00:00 GMT-0600 (Central Standard Time) 1 Sun Mar 14 2010 01:00:00 GMT-0600 (Central Standard Time) </code></pre> <p>However, changing the last line of the for loop to</p> <pre><code>date = new Date(date.getTime() + 3600000) </code></pre> <p>produces the output I'd expect with the skipped hour at the transition:</p> <pre><code>21 Sat Mar 13 2010 21:00:00 GMT-0600 (Central Standard Time) 22 Sat Mar 13 2010 22:00:00 GMT-0600 (Central Standard Time) 23 Sat Mar 13 2010 23:00:00 GMT-0600 (Central Standard Time) 0 Sun Mar 14 2010 00:00:00 GMT-0600 (Central Standard Time) 1 Sun Mar 14 2010 01:00:00 GMT-0600 (Central Standard Time) 3 Sun Mar 14 2010 03:00:00 GMT-0500 (Central Daylight Time) 4 Sun Mar 14 2010 04:00:00 GMT-0500 (Central Daylight Time) 5 Sun Mar 14 2010 05:00:00 GMT-0500 (Central Daylight Time) 6 Sun Mar 14 2010 06:00:00 GMT-0500 (Central Daylight Time) 7 Sun Mar 14 2010 07:00:00 GMT-0500 (Central Daylight Time) 8 Sun Mar 14 2010 08:00:00 GMT-0500 (Central Daylight Time) 9 Sun Mar 14 2010 09:00:00 GMT-0500 (Central Daylight Time) </code></pre> <p>What is the reason the the first approach doesn't work?</p> <p>Edit: Additionally, with a DST transition with a duplicated hour it seems to just ignore the duplicated hour with the first approach: The other thing is that if I try it with a DST transition with a duplicated hour it just seems to ignore the duplicated hour:</p> <pre><code>Sun Nov 07 2010 00:00:00 GMT-0500 (Central Daylight Time) Sun Nov 07 2010 01:00:00 GMT-0600 (Central Standard Time) Sun Nov 07 2010 02:00:00 GMT-0600 (Central Standard Time) </code></pre> <p>But it correctly handles the duplicated hour with the second approach.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload