zod
zod copied to clipboard
[Date] Parsing of DateOnly strings
3.20 introduced z.string().DateTime()
for cleaner string->DateTime parsing. However, it only supports strings containing both Date and Time
An API I'm working with includes only the Date part (today would be 2022-12-12
). This API is written in C# using the DateOnly struct.
The built-in JavaScript new Date(<string>)
does work with DateOnly strings, so I don't see a huge reason not to support it as well. I don't know what the API for it would be though, but the two most obvious ones that I could think of are the following:
- An additional option in the
string().DateTime()
function:dateOnly: boolean
- A separate
string().Date()
function (orstring().DateOnly()
)
(As an aside, C# also has a TimeOnly struct, but I don't really see how that would be parseable into a JavaScript primitive)
Small correction - z.string().datetime()
still returns a string, not a Date
. I'm in favor of adding .date()
and .time()
methods for convenience, though using .regex
for these is pretty straightforward as well.
I'm in favor of adding
.date()
and.time()
methods for convenience.
Can I take a shot at these?
Can I take a shot at these?
If you're asking for permission to submit a PR, please do. PRs are always welcome. Thanks.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Not stale bro..
Hey there @colinhacks!
Any ETA on the release of @igalklebanov's PR?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Not stale bro.
Any update on this?