fix: support unqualified (local) datetime strings
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.
const datetime = z.string().datetime();
datetime.parse("2020-01-01T00:00:00"); // fail, same as before, requires trailing "z"
const datetimeUnqualified = z.string().datetime({ unqualified: true });
datetime.parse("2020-01-01T00:00:00"); // pass
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.
Deploy Preview for guileless-rolypoly-866f8a ready!
Built without sensitive environment variables
| Name | Link |
|---|---|
| Latest commit | 7cff53a2723935389fc5947036b5a0b2a7999567 |
| Latest deploy log | https://app.netlify.com/sites/guileless-rolypoly-866f8a/deploys/653c880faeb4b50008fce1e2 |
| Deploy Preview | https://deploy-preview-2913--guileless-rolypoly-866f8a.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
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!