yup.date().cast doesn't handle ISO 8601 date strings before epoch

Created on 28 Dec 2019  路  3Comments  路  Source: jquense/yup

Describe the bug
Documentation states: "By default ISO date strings will parse correctly." but casting ISO strings representing dates before epoch (e.g. "1969-06-20T20:17:00.000Z") will produce an error:

Uncaught TypeError: The value of field could not be cast to a value that satisfies the schema type: "date". 

attempted value: 1969-06-20T20:17:00.000Z 
result of cast: Invalid Date

To Reproduce
https://codesandbox.io/s/trusting-cloud-7bbv7

Expected behavior
Valid ISO 8601 dates should be parsed properly regardless of whether they represent pre-epoch dates.

Platform (please complete the following information):

  • Browser any

Additional context
This bug has been introduced in yup 0.28.0. It was not present in 0.27.0.

Most helpful comment

PR https://github.com/jquense/yup/pull/655 seems to be broken. I think instead of

-return value ? ...
+return value > -1 ? ...

it should be

-return value ? ...
+return !isNaN(value) ? ...

All 3 comments

PR https://github.com/jquense/yup/pull/655 seems to be broken. I think instead of

-return value ? ...
+return value > -1 ? ...

it should be

-return value ? ...
+return !isNaN(value) ? ...

ISO date validation seems definitely broken in 0.28. I'm back to 0.27 and its working fine now.

PR #655 seems to be broken. I think instead of

-return value ? ...
+return value > -1 ? ...

it should be

-return value ? ...
+return !isNaN(value) ? ...

I completely agree with this.

I'm having errors while validating dates before 01/01/1970, as all those dates have a negative value on the UNIX system.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jakke-korpelainen picture jakke-korpelainen  路  4Comments

ceilat picture ceilat  路  3Comments

you-fail-me picture you-fail-me  路  4Comments

aprat84 picture aprat84  路  4Comments

ScreamZ picture ScreamZ  路  4Comments