Open oliviercperrier opened 1 year ago
Same is for _-1-01
There are a lot of wonky edge cases here, which seem to be related to how the native Date constructor handles parsing strings. For example, even a "well formed" date like "12-22-0088" is coerced to Thu Dec 22 1988 when passed to Date
.
As a workaround, we overrode the default transform and parsed the date with date-fns
: https://codesandbox.io/s/yup-playground-forked-2-t0j5vd?file=/src/index.js. Ideally we'd apply this globally to all date
schemas, but I didn't spend much time investigating if that was possible.
I can confirm the "well formed" exemple from @chawes13 :
My workaround
yup
.date()
.transform((_, originalValue) => new Date(originalValue))
....
Describe the bug
The yup.date() schema is returning these date are valid:
To Reproduce
https://codesandbox.io/s/young-star-ke5v6k
Expected behavior
This date should not be valid and the schema validation should return an error.
Platform (please complete the following information):