I am validating the date and time with moment().isValid()
, but the date and time validation at 24:00:00 does not work as expected.
console.log(moment('2020-07-02 24:00:00','YYYY-MM-DD HH:mm:ss',true).isValid());
I want the result of the above code to be false
, but the actual behavior is true
.
How can I implement the above phenomenon to get the expected result?
We also conducted tests on parts that seemed to be related, but the behavior at 60 minutes, 60 seconds, etc. was as expected.
// 24:00:00
console.log(moment('2020-07-02 24:00:00').isValid()); //true
console.log(moment('2020-07-02 24:00:00','YYYY-MM-DD HH:mm:ss').isValid()); //true
console.log(moment('2020-07-02 24:00:00','YYYY-MM-DD HH:mm:ss',true).isValid()); //true (Unexpected)
console.log(moment('2020-07-02 24:00:00','YYYY-MM-DD hh:mm:ss',true).isValid()); //false
console.log(moment('2020-07-02 24:00:00','YYYY-MM-DD kk:mm:ss',true).isValid()); //true
// other
console.log(moment('2020-07-02 24:00:01','YYYY-MM-DD HH:mm:ss',true).isValid()); //false
console.log(moment('2020-07-02 24:01:00','YYYY-MM-DD HH:mm:ss',true).isValid()); //false
console.log(moment('2020-07-02 23:58:60','YYYY-MM-DD HH:mm:ss',true).isValid()); //false
console.log(moment('2020-07-02 23:59:60','YYYY-MM-DD HH:mm:ss',true).isValid()); //false
console.log(moment('2020-07-02 22:60:00','YYYY-MM-DD HH:mm:ss',true).isValid()); //false
console.log(moment('2020-07-02 23:60:00','YYYY-MM-DD HH:mm:ss',true).isValid()); //false
console.log(moment('2020-07-02 23:60:60','YYYY-MM-DD HH:mm:ss',true).isValid()); //false