Date Object Doesn't Work.

Norbert Lindenberg ecmascript at lindenbergsoftware.com
Wed May 28 23:58:48 PDT 2014


As Luke phrased it two years ago: “The current [ES 5.1] spec text allows implementations to be as wrong as they'd like about daylight savings adjustments, but constrains how correct they should try to be.  This is somewhat counterintuitive, and in practice, has not succeeded in producing consensus between browsers.” [1]

The ES6 spec [2, 3] has since been changed to encourage implementors to use best available information, but maybe implementors haven’t taken advantage of this yet. Bug reports against the implementations may help.

[1] https://mail.mozilla.org/pipermail/es-discuss/2012-March/020830.html
[2] http://people.mozilla.org/~jorendorff/es6-draft.html#sec-local-time-zone-adjustment
[3] http://people.mozilla.org/~jorendorff/es6-draft.html#sec-daylight-saving-time-adjustment

Norbert
 

On May 28, 2014, at 16:36 , Garrett Smith <dhtmlkitchen at gmail.com> wrote:

> Yesterday, I posed the question about an event starts at 2am, 2014,
> and ends immediately
> after 3 am, on May 9, how long is it?
> 
> The event, in that case, should be 23 hours due to 1h DST loss.
> ("spring forward"). But then I noticed more anomalies:
> 
> <!doctype html>
> <head>
> <title>test DST 1</title>
> 
> <style>
> head, script {
>  display: block;
>  white-space: pre;
>  font-family: monospace;
> }
> </style>
> <script>
> var d = new Date(2013, 02, 10),
>    d2 = new Date(2013, 02, 10);
> d.setHours(1);
> d2.setHours(2);
> 
> function showResult() {
>  document.getElementById("out").
>    firstChild.data =
>      "d: " + d.toString()
>      + "\nd2: " + d2.toString()
>      + "\nd2 - d: " + (d2 - d)
> }
> window.onload = showResult;
> </script>
> </head>
> 
> <h2>result</h2>
> <pre id='out'>-</pre>
> </body>
> </html>
> 
> Chrome, Opera:
> d: Sun Mar 10 2013 01:00:00 GMT-0800 (PST)
> d2: Sun Mar 10 2013 01:00:00 GMT-0800 (PST)
> d2 - d: 0
> 
> Safari:
> d: Sun Mar 10 2013 01:00:00 GMT-0800 (PST)
> d2: Sun Mar 10 2013 03:00:00 GMT-0700 (PDT)
> d2 - d: 3600000
> 
> Firefox:
> d: Sun Mar 10 2013 01:00:00 GMT-0800 (PDT)
> d2: Sun Mar 10 2013 03:00:00 GMT-0700 (PDT)
> d2 - d: 3600000
> 
> What are Opera and Chrome doing?
> 
> Here in CA, we recognize DST, and so 0 would be wrong, as 2am gets set
> forward to 3am but the offset changes, too.
> 
> I believe Safari is correct here.
> 
> Now from 2am - 3am, the difference should be 0 because 2am gets set
> forward to 3am.
> 
> <!doctype html>
> <head>
> <title>test DST 2</title>
> 
> <style>
> head, script {
>  display: block;
>  white-space: pre;
>  font-family: monospace;
> }
> </style>
> <script>
> var r = new Date(2013, 02, 10),
>    r2 = new Date(2013, 02, 10);
> r.setHours(2);
> r2.setHours(3);
> 
> function showResult() {
>  document.getElementById("out").
>    firstChild.data =
>      "r: " + r.toString()
>      + "\nr2: " + r2.toString()
>      + "\nr2 - d: " + (r2 - r)
> }
> window.onload = showResult;
> </script>
> </head>
> 
> <h2>result</h2>
> <pre id='out'>-</pre>
> </body>
> </html>
> 
> 
> Firefox:
> r: Sun Mar 10 2013 03:00:00 GMT-0700 (PDT)
> r2: Sun Mar 10 2013 03:00:00 GMT-0700 (PDT)
> r2 - d: 0
> 
> Safari:
> r: Sun Mar 10 2013 03:00:00 GMT-0700 (PDT)
> r2: Sun Mar 10 2013 04:00:00 GMT-0700 (PDT)
> r2 - d: 3600000
> 
> Opera, Chrome:
> r: Sun Mar 10 2013 01:00:00 GMT-0800 (PST)
> r2: Sun Mar 10 2013 03:00:00 GMT-0700 (PDT)
> r2 - d: 3600000
> 
> Firefox seems to get this right, forwarding 2am to 3am.
> 
> What is going on with the others?
> -- 
> Garrett
> @xkit
> ChordCycles.com
> garretts.github.io
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



More information about the es-discuss mailing list