-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Dates: Accept ISO-8601 format, and use UTC milliseconds as the backend #1194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
We still interpret JS date objects according to the date and hour they have in the local timezone, and for backward compatibility we shift milliseconds (in ranges etc) by the local/UTC offset.
@@ -21,6 +20,11 @@ var ONEHOUR = constants.ONEHOUR; | |||
var ONEMIN = constants.ONEMIN; | |||
var ONESEC = constants.ONESEC; | |||
|
|||
var DATETIME_REGEXP = /^\s*(-?\d\d\d\d|\d\d)(-(0?[1-9]|1[012])(-([0-3]?\d)([ Tt]([01]?\d|2[0-3])(:([0-5]\d)(:([0-5]\d(\.\d+)?))?(Z|z|[+\-]\d\d:?\d\d)?)?)?)?)?\s*$/m; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you cook this up yourself or find from a google search? If the latter, can you paste the reference above?
'2015-01-01 12:00:60', '2015-01-01 12:00:-1', '2015-01-01 12:00:001', '2015-01-01 12:00:1' // bad second | ||
'2015-01-01 12:00:60', '2015-01-01 12:00:-1', '2015-01-01 12:00:001', '2015-01-01 12:00:1', // bad second | ||
'2015-01-01T', '2015-01-01TT12:34', // bad ISO separators | ||
'2015-01-01Z', '2015-01-01T12Z', '2015-01-01T12:34Z05:00', '2015-01-01 12:34+500', '2015-01-01 12:34-5:00' // bad TZ info |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good.
[ | ||
new Date(0), | ||
new Date(2000), | ||
new Date(2000, 0, 1), | ||
new Date(), | ||
new Date(-9999, 0, 1), | ||
new Date(9999, 11, 31, 23, 59, 59, 999) | ||
new Date(-9999, 0, 3), // we lose one day of range +/- tzoffset this way |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for that comment
@@ -489,7 +489,7 @@ describe('Test shapes', function() { | |||
title: 'linked to date and category axes', | |||
xaxis: { | |||
type: 'date', | |||
range: ['2000-01-01', (new Date(2000, 1, 2)).getTime()] | |||
range: ['2000-01-01', '2000-02-02'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good 💃
I'm thinking it would be nice to make http://codepen.io/plotly/pen/grdEaN (from #811) part of our image tests. Non-blocking if you feel that the jasmine tests are sufficient.
"xaxis4": {"anchor": "y4"}, | ||
"xaxis5": {"anchor": "y5"}, | ||
"xaxis6": {"anchor": "y6"}, | ||
"xaxis7": {"anchor": "y7"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@etpinard good point about including the UTC behavior in the mocks. I replaced the simple date_axes.json
with this one that includes tick scales all the way from full years to partial seconds.
First part: ISO-8601:
fixes #1003
For simplicity, I ended up separately allowing the date/time separator to be space, t, or T, and a timezone spec at the end - ie timezones are now accepted for our normal space-separated format too.
Also @etpinard a perf note - I switched from the manual string chopping we had before to a regexp-based conversion. When I originally wrote this converter a few years ago it was clearly faster to do it manually, but now either because our patterns have gotten more complicated, or browsers have improved their regexp engines, it's faster this way. It's also a lot shorter code-wise (though I wouldn't exactly call it nicer to look at, with that mile-long regexp!)
On Chrome, the old way (extended to ISO-8601) was taking ~2microsec per conversion, the new way is ~1.3microsec. FF is quite a bit slower at both versions, but the regexp is faster there too: ~6.8microsec vs ~10.7microsec.
The rest: use UTC milliseconds as the back end:
Changes our internal date linearization to use UTC rather than local milliseconds. Every day on a Plotly graph will now be 24 hours long, with no daylight shifts.
Note that for backward compatibility I still have us treat millisecond values (in ranges etc) as they were calculated previously, in local time, and shift them to UTC. I do the same thing with js date objects, on the theory that users generally construct these by using new Date(y, m, d, H, M, S, ms) with the date/time components they expect to see on the final graph.
If and when we add support for explicit timezone settings, we can do smarter things for users who specify a timezone, but I think this should remain the default behavior.
Fixes #171 and #811
This PR supersedes #1158 and #1172