Skip to content
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

How to parse Dates in Api with zod #46

Closed
rbakaou opened this issue May 4, 2020 · 2 comments
Closed

How to parse Dates in Api with zod #46

rbakaou opened this issue May 4, 2020 · 2 comments

Comments

@rbakaou
Copy link

rbakaou commented May 4, 2020

Hi, Great wrok with zod. maybe i'm using it wrong but how would i parse a date in Api params i would get a string of Date and Zod expects a Date object. Should i use the zod.string() and parse the date in the backend?

@colinhacks
Copy link
Owner

colinhacks commented May 4, 2020

Yes, I'd recommend using a string field. If you want to verify that the string is, say, a valid ISO date string, then use a custom validator in combination with something like validator.js to enforce that. 👍

I wasn't initially planning to support Date schemas at all since they're not easily serializable but they were requested by multiple people. I think dealing with dates as ISO strings (until you actually need to display them in a human-readable format) is far more intuitive.

@rbakaou
Copy link
Author

rbakaou commented May 4, 2020

Thanks Awesome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants