-
Notifications
You must be signed in to change notification settings - Fork 0
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
Improve Date types #5
Comments
This one is pretty big. I've documented my current plan in the README below. I will probably tackle one type at a time because each one has nuances and a single PR for all types would be too big. That said, I've already completed a lot of it and will PR progressive chunks from branches named Config{
"host": "127.0.0.1",...
"datetime": {
"useDate": false,
"useIso": true,
"coerce" : false,
"offset": true,
"precision": 3,
"minDate": "1900-01-01",
"maxDate": "2099-12-31",
"year" : "/^\\d{4}$/"
}
}
Date and Time typesMySQL date and time types include DATE, DATETIME, TIMESTAMP, and YEAR. MySQL accepts, stores, and returns different formats for dates and times. Years may be 1-4 digits or a string. Time may or may not have sub-second precision. User data from a browser form or other sources may be a string or Date object, and subject to other formats. Even if the database accepts, for example, a 2 digit year for a YEAR type in the range of 0 to 99, application rules may require values to be provided as 4 digit years or from 2020 to 2030. You may not wish data coming from from the database to validate in the context of your application, even if the database somehow has those values already stored. MySQL-Zod defaults to validating with a single rule
References
|
I think you overcomplicated this. A much better approach would be letting the user programmatically define which zod schema for each field type |
Zod supports
z.date()
. mysql-zod saves date/time asz.string()
.The text was updated successfully, but these errors were encountered: