I’m making a module that uses dates, and I need to check if dates are valid, e.g. 29. february 1999 is not a valid date, since 1999 was not a leap year, but 29. february 1996 is a valid date since 1996 was a leap year.
The Js.Date library got the function
getDate that will return NaN if the date is invalid. I have tried to use this together with
Js.Float.isNaN, but it does not seem to work as a validator for dates, since it returns 29. february 1999 as valid date:
Js.Date.makeWithYMD(~year=1999., ~month=2., ~date=29., ()) |> Js.Date.getDate |> Js.Float.isNaN /* => false */
Does anyone know how to check if a date is valid in ReasonML? I know this is possible with moment, e.g. would
moment('29021999', 'DDMMYYYY').isValid() return
false, but I would like to avoid third party libraries if possible.