Why does date.js allow a date with one signed year when using strict parsing?

I am using moment.js to parse a date. http://momentjs.com/docs/#/parsing/string-format/

This is validating and converting the date to the format required by my database. In my testing, I came across this input date "6-4-3" which shouldn't be valid with the given format.

moment('6-4-3','YYYY-MM-DD',true).isValid(); //returns true


Total date in the moment object "Mon Apr 03 0006 ...". When I call isValid it returns true. I think this date should be considered invalid as it contains too few digits for each part of the format string.

I added regex.test to my code to ensure the dates have the correct number of digits, but I think this should be handled differently in moment.js when strict is true.

Is there something I am missing here? Isn't this a matter of rigorous parsing? Or is there a reason why this is the intended behavior?


source to share

1 answer

This was a known issue for past versions of Moment.js: YYYY-MM-DD with a three-digit year returns true for isValid () .

This was fixed in December 2013 and your code works as expected with the most recent version of the library. Version 2.3.1 was released in October 2013 and does not include this hotfix.



All Articles