-
Notifications
You must be signed in to change notification settings - Fork 134
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
Bugs in Date scalar #826
Comments
For the first problem you reported, I tried to reproduce it but For the second one, you can try If I'm missing something, I'd appreciate if you create failing tests for those cases. |
Hi @ardatan, for the first problem. I did encounter "Invalid Date" in my backend (the answer passed through the Graphql layer raw, without any date manipulation) a while ago. Because I didn't realize there's
For the second "problem", thanks for pointing me out about Aside, another scalar that I roll out is the ObjectId (after reading #429), since my project already includes mongodb as a dependency -- it would be nice if this libary's ObjectId would wrap the string into a mongodb.ObjectId. |
Hi. I'm been trying to use the Date scalar, and I found 2 problems related to it.
Problem 1:
The Date scalar accepts value like '2021-07-32', but then when it's turned to
new Date()
, the Date constructor returns 'Invalid Date' which doesn't throw exceptions. The Graphql layer should not let such values get pass its validators.The problem is that https://github.com/Urigo/graphql-scalars/blob/master/src/scalars/iso-date/validator.ts doesn't check for months that have 31 days.
Problem (?) 2:
new Date("2020-01-01")
returns a Date with 0 hour offset, assuming to be UTC. While this works for production servers that use UTC, it breaks date manipulation indate-fns
, which uses local time zone, when I'm running the server locally for development. This one might not be a real problem but my choice of library. However, imagine the following:I don't think this is what you'd want either. One possible fix is, since you already have the
year
,month
,day
parts, you can returnnew Date(year, month - 1, day)
instead ofnew Date(date /* string */)
.The text was updated successfully, but these errors were encountered: