Date.parse should treat ISO 8601 milliseconds part as fraction of a second. #147

merged 2 commits into from May 10, 2013


None yet
3 participants

angelyordanov commented Dec 18, 2012

I've noticed that the shim implementation of Date.parse was not parsing ASP.NET Web API generated JSON dates which look like this - "2012-12-18T10:33:01.4300913+02:00".

The problem appeared to be the extra digits in the millisecond part.

After some investigation and checking the ISO8601 spec( it turns out that the numbers after the "." are not the actual milliseconds but a fraction of a second.

Here is what the spec says. Representations with decimal fraction
If necessary for a particular application a decimal fraction of hour, minute or second may be included. If a decimal fraction is included, lower order time elements (if any) shall be omitted and the decimal fraction shall be divided from the integer part by the decimal sign specified in ISO 31-0, i.e. the comma [,] or full stop [.]. Of these, the comma is the preferred sign. If the magnitude of the number is less than unity, the decimal sign shall be preceded by two zeros in accordance with 3.6.
The interchange parties, dependent upon the application, shall agree the number of digits in the decimal fraction. The format shall be [hhmmss,ss], [hhmm,mm] or [hh,hh] as appropriate (hour minute second, hour minute, and hour, respectively), with as many digits as necessary following the decimal sign. A decimal fraction shall have at least one digit. In the examples below it has been agreed to give the smallest time element a decimal fraction with one digit.

All browsers I've checked (IE10,IE9, Latest Chrome, Firefox, Opera) support this.

The spec defines fractions from hours and minutes as well but no browser does support this.

I have implemented a fix and added tests to cover this.

Let me know what you think.


Yaffle commented Dec 18, 2012

it is better to use Number(".12341245434") to convert subseconds part to a number


angelyordanov commented Dec 18, 2012

Yup, it's way better since it is in that format to begin with.

@kriskowal kriskowal added a commit that referenced this pull request May 10, 2013

@kriskowal kriskowal Merge pull request #147
With regard to parsing fractional seconds.

@kriskowal kriskowal merged commit 00438f6 into es-shims:master May 10, 2013


kriskowal commented May 10, 2013

Thank you for the contribution.

@Yaffle Would you like to take on the responsibility of reviewing, cross-testing, and merging all Date related fixes? I trust your judgement.


Yaffle commented May 11, 2013


kriskowal commented May 11, 2013

@Yaffle I’ve given you Collaborator status on this repository. That should do the trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment