Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date and DateTime Validation #2107

Open
jmc420 opened this issue Aug 31, 2023 · 1 comment
Open

Date and DateTime Validation #2107

jmc420 opened this issue Aug 31, 2023 · 1 comment

Comments

@jmc420
Copy link

jmc420 commented Aug 31, 2023

I cannot get the Date or DateTime scalars to work. I can see why it is not working because the REGEX is rejecting the string being producted by JSON.stringify. I'm am creating an input object with a Date field that is initialised with new Date(). In the fetch the JSON.stringify converts the date object into "2023-08-31T16:57:53.991Z".

If I pass a Date with the format: "2023-08-31T16:57:53.991Z" to either the Date or DateTime scalars, the REGEX expressions in validator.js fails.

In validateDate the REGEX is

const RFC_3339_REGEX = /^(\d{4}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01]))$/;

in ValidateDateTime the REGEX is:

const RFC_3339_REGEX = /^(\d{4}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60))(.\d{1,})?(([Z])|(+|-:[0-5][0-9]))$/;

This REGEX works fine:

const RFC_3339_REGEX = /^((?:(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2}(?:.\d+)?))(Z|[+-]\d{2}:\d{2})?)$/;

(see https://regex101.com/r/qH0sU7/1).

Is this a fault with the vaildation REGEX or with the way I am using the scalars?

@a-type
Copy link

a-type commented Apr 1, 2024

Agreed, it's baffling that DateTime can't parse any of the built-in string formats supplied by Javascript's own Date!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants