zod icon indicating copy to clipboard operation
zod copied to clipboard

fix: support unqualified (local) datetime strings

Open 0xturner opened this issue 2 years ago • 4 comments

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.

0xturner avatar Oct 27 '23 23:10 0xturner

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...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] avatar Oct 27 '23 23:10 netlify[bot]

Hi I got this issue with the datetime, do you know when this fix will be release please

Lephilosophe237 avatar Oct 31 '23 18:10 Lephilosophe237

any updates on when this is getting merged ?

ahmed-abdelmotey avatar Nov 26 '23 18:11 ahmed-abdelmotey

can we get this merged?

Irvenae avatar Jan 29 '24 08:01 Irvenae

Please, any feedback at least, guys, why it's not merged yet?

ezze avatar Mar 29 '24 23:03 ezze

Also interested in this change - would save a lot of headaches when working with forms with datetime inputs.

ericdew avatar Apr 04 '24 02:04 ericdew

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!

colinhacks avatar Apr 13 '24 00:04 colinhacks