-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
fix: support unqualified (local) datetime strings #2913
Conversation
✅ Deploy Preview for guileless-rolypoly-866f8a ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
9a161f7
to
6a12c5a
Compare
6a12c5a
to
7cff53a
Compare
@@ -709,7 +709,7 @@ z.string().regex(regex); | |||
z.string().includes(string); | |||
z.string().startsWith(string); | |||
z.string().endsWith(string); | |||
z.string().datetime(); // ISO 8601; default is without UTC offset, see below for options | |||
z.string().datetime(); // ISO 8601; default is UTC with zero offset, see below for options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choosing more explicit wording here.
"Without UTC offset" is potentially misleading, as there is some nuance in the fact that "Z" is a zone indicator for the zero UTC offset, as opposed to the absence of an offset.
@@ -535,6 +535,7 @@ export type ZodStringCheck = | |||
kind: "datetime"; | |||
offset: boolean; | |||
precision: number | null; | |||
unqualified: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some other names I considered for this option, open to changing:
local
utc
(defaults to true, set to false to allow unqualified dates)
Hi I got this issue with the datetime, do you know when this fix will be release please |
any updates on when this is getting merged ? |
can we get this merged? |
Please, any feedback at least, guys, why it's not merged yet? |
Also interested in this change - would save a lot of headaches when working with forms with datetime inputs. |
Thanks @0xturner — I ended up merging the other PR after modifying it to use an approach/API almost identical to yours 😅 Whoops. Great stuff here! |
FIxes #2385
Adds support for local unqualified date time strings. (the ones that don't end in "Z")
ISO-8601 allows unqualified date time strings, in which case the time is assumed to be in local time rather than UTC. (See)
To prevent breaking changes, this is an an additional opt-in option to the existing
string().dateTime()
method.I realized shortly after creating this PR that there is a similar effort at #2522. I've taken a slightly different approach in this PR. I am not sure what the etiquette is in terms of duplicate PRs, happy to collaborate and merge efforts with #2522 if that is possible/preferred.