Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
71
rated 0 times [  75] [ 4]  / answers: 1 / hits: 16914  / 11 Years ago, wed, september 25, 2013, 12:00:00

Running moment.js, 2.2.1



moment(2010-10-319, [YYYY-MM-DD]).isValid()


... returns true, and the moment object would be set to 31 October 2010. The parser seems to strip extraneous characters of any sort:



moment(2010-10-31a, [YYYY-MM-DD]).isValid(); // true


Curiouser, if you add additional format choices, then the stripping becomes limited to only one character! (Shouldn't the format strings tests be ORed?)



moment(2010-10-319, [MM/DD/YYYY, MM-DD-YYYY, YYYY-MM-DD]).isValid(); // true
moment(2010-10-3199, [MM/DD/YYYY, MM-DD-YYYY, YYYY-MM-DD]).isValid(); // false (!!!)


Is this behaviour by design? I'm not getting why.



EDIT: A commenter found another case where extra characters beyond one are, indeed, stripped:



moment(2010-10-319qr, [MM/DD/YYYY, MM-DD-YYYY, YYYY-MM-DD]).isValid(); // true (!)


Here is is in action: http://jsfiddle.net/grahampcharles/r42jg/6/ (updated with new case)


More From » date

 Answers
12

create an Issue on the Git Repository from momentjs https://github.com/moment/moment/ the best way to handle this error.


[#75454] Tuesday, September 24, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
matteo

Total Points: 81
Total Questions: 100
Total Answers: 96

Location: Honduras
Member since Sat, Jul 24, 2021
3 Years ago
;