How do I parse a Date with moment.js(or alternative library) to pick out 31st Feb or 31st June e,t,c, as invalid?
I know that if I did
moment("20-02-2000");
it says
Moment {_isAMomentObject: true, _i: "20-02-2000",
_isUTC: false, _locale: Locale, _d: Invalid Date}
So it can detect an invalid date, that's good
Though i'm using yyyy-mm-dd
I don't seem to be able to get it to parse a Date
moment("2000-02-31");
Moment {_isAMomentObject: true, _i: "2000-02-31",
_f: "YYYY-MM-DD", _isUTC: false, _pf: Object…}
^^ nothing about invalid date there
moment("2000-02-40");
Moment {_isAMomentObject: true, _i: "2000-02-40",
_f: "YYYY-MM-DD", _isUTC: false, _pf: Object…}
^^ nothing about invalid date there
moment("2000-40-01");
Moment {_isAMomentObject: true, _i: "2000-40-01",
_f: "YYYY-MM-DD", _isUTC: false, _pf: Object…}
^^ nothing about invalid date there
added
var v=moment("2000-02-31");
v.toDate()
Thu Mar 02 2000 00:00:00 GMT+0000 (GMT Standard Time)
^^ I see that if I give an invalid date like 31st feb, that it normalizes it, but I want it to just say invalid.
I'm looking for a function where I give it "2000-31-02" it says invalid date.
I have seen moment.js suggested as an alternative to javascript's Date constructor. I looked at moment.js because javascript's Date constructor also parses 31st Feb without saying invalid javascript Date.parse assumes 31 days in February and all months? . So I was hoping that moment.js would be able to do it. If it can, then how? And if not, then is there an alternative to moment.js that does it?
I'm looking for a library I can import, rather than reinventing the wheel.