0

While creating/testing a date adapter in my Angular project I ran into this issue. I think I must be missing some convention, but when changing the month to a single digit like 2 (for February) rather than 02, I get a different day.

Date.parse is giving two different outputs based on that different as pictured below. Any thoughts?

Date parse

Pezetter
  • 2,783
  • 2
  • 22
  • 40
  • the month argument counts starting from zero. [read more](https://stackoverflow.com/q/2552483/6108211) – Dmitry Grinko Apr 02 '19 at 15:49
  • 1
    i dont think month stating from 0 explains it – dasfdsa Apr 02 '19 at 15:53
  • The parmeter should be -- "A string representing a simplification of the ISO 8601 calendar date extended format (other formats may be used, but results are *implementation-dependent*)". Refer the [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse#Parameters). – 31piy Apr 02 '19 at 15:53
  • Giving a date that's off by five hours when the month is formatted incorrectly seems like a pretty weird implementation to me :p -- but yeah, we should stick to the spec'd format to keep the weirdness at bay. – Cat Apr 02 '19 at 15:58

1 Answers1

0

According to the documentation:

The ECMAScript specification states: If the String does not conform to the standard format the function may fall back to any implementation–specific heuristics or implementation–specific parsing algorithm.

Here, the second string does not match the expected format, and Chrome does something with it.

If you test it with Firefox, the same date is returned, so it's a Chrome "issue".

You can try to read V8's source code to understand why you get this and how it is actually implemented.

This isn't a lot of help, but I don't think you'll find anything without getting to the bottom of V8.

sjahan
  • 5,720
  • 3
  • 19
  • 42