ES6 Date parsing
The behavior or parsing a date or date+time string to a Date object (using the new Date(string) constructor, or Date.parse(string) function) is changed in ES6. AFAIK, this isn't currently handled by the core-js ES6 polyfills. Should it be? My understanding is that this is a dependency for libraries such as Babel. (originally filed as babel/babel#1418)
Behavior
If the time zone offset is absent, the date-time is interpreted as a local time.
The value of an absent time zone offset is "Z".
To get ES6 behavior out of ES5, the string would need to be mutated to be interpreted in local time. The polyfill would have to be careful only to do this for the specific use cases affected.
| ES6 | ES5 |
|---|---|
new Date("2014-12-31") |
new Date("2014/12/31") |
new Date("2014-12-31T01:23:45") |
new Date("2014/12/31 01:23:45") |
new Date("2014-12-31T01:23:45Z") |
no change |
new Date("2014-12-31T01:23:45-05:00") |
no change |
Note, the hyphens are replaced with slashes, but still kept in year/month/day order to prevent internationalization ambiguities. Also note the T removed. Also note that ECMAScript only defines the ISO8601/RFC3339 format, leaving everything else implementation specific. It just happens that all major implementations support the formats I showed.
Possible, but not in near future.
If this were to happen, one interesting/tricky case is:
new Date("2015")
It has no dashes or slashes -- to force this to local time in ES5 I think you'd want to say this:
new Date("2015/01")
I'm not sure if this works in every browser, but so far it does in Chrome:
new Date("2014-12-31 GMT-0600")
new Date("2015 GMT-0600")
This works with most dates. Doesn't work with ISO, but this works:
2014-12-31T01:23:45+0600
So instead of trying to change the format you could try adding the missing timezone.
https://github.com/tc39/ecma262/issues/87
NB https://github.com/Yaffle/date-shim