question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request: ZodDate min and max

See original GitHub issue

I’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:closed
  • Created a year ago
  • Reactions:9
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Svishcommented, Jun 20, 2022

Wanting to use zod instead of yup, 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.

0reactions
Balastrongcommented, Jun 24, 2022

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! 😃

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found