Request: ZodDate min and max
See original GitHub issueI’m happy to give this a shot myself if you think it’s worthwhile to add!
I get that this can currently be achieved with a refinement:
z.date().refine((d) => d >= new Date("2020-01-01") && d <= new Date("2030-01-01"))
… but it seems like a reasonable top-level concept to me:
z.date().min(new Date("2020-01-01")).max(new Date("2030-01-01"))
Issue Analytics
- State:
- Created a year ago
- Reactions:9
- Comments:6 (2 by maintainers)
Top Results From Across the Web
colinhacks/zod: TypeScript-first schema validation ... - GitHub
Zod is a TypeScript-first schema declaration and validation library. I'm using the term "schema" to broadly refer to any data type, from a...
Read more >Data validation with automatic typing using zod - CodeX Team
Advanced validation of strings and numbers. With zod we can set rules for length, format (url, email, uuid), minimum and maximum values and...
Read more >How get values inside min(), max() in zod? - Stack Overflow
Yes, after a little poking around, there's a hidden _def field that you probably need to //@ts-ignore : const minValue = schema.shape.name.
Read more >Logic for Picking the Requested Delivery Date to Min Max ...
What is the Logic of picking the Requested delivery date in Min Max setup? Solution. Sign In. To view full details, sign in...
Read more >Schema validation in TypeScript with Zod - LogRocket Blog
In this article, you will learn about schema design and validation in Zod and how to run it in a TypeScript codebase at...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Wanting to use
zod
instead ofyup
, but I’m really missing this feature as well. We’re dealing with several forms, most of them have at least one date field, and I don’t think a single one of them are without a minimum or a maximum date. It’s basically always “pick a date in the past” (like, a date of birth) or “pick a date in the future” (like, when do you need this thing you’re requesting).If it for some reason won’t be added to the library, maybe because you don’t want to tie it to a specific date-library, which is fair, it would at least be good if there were good examples in the docs about how to do it with a few common date-libraries.
The check was already inclusive by default but indeed it wasn’t properly handled in the code. I update the PR, thank you for pointing it out! 😃