jquense / yup

Dead simple Object schema validation
MIT License
22.95k stars 935 forks source link

Fix date parsing to match docs and support timestamps #2057

Open pgjones opened 1 year ago

pgjones commented 1 year ago

The yup documentation states

The default cast logic of date is pass the value to the Date
constructor, failing that, it will attempt to parse the date as an
ISO date string.

which wasn't true and would manifest for timestamps i.e.

const schema = yup.date();
schema.validateSync(1411500325000) // Failed to validate

as the cast logic would try Date.parse(1411500325000) which would return an invalid date.