- Notifications
You must be signed in to change notification settings - Fork942
feat(string): Create .datetime()#2087
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
@jquense is this something you would consider? |
Unlike `.date()`, `datetime` will not convert the string to a `Date` object. `datetime` also provides greater customization over the required format of the datetime string than `date` does. | ||
`options.allowOffset`: Allow a time zone offset. False requires UTC 'Z' timezone. _(default: false)_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
why default to false for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
My thinking was that most of the time when you store an iso date in a DB (which in my mind will be the most common use case for this function) you would want them to be consistently formatted in UTC time for easy comparison.
src/string.ts Outdated
/** Allow a time zone offset. False requires UTC 'Z' timezone. (default: false) */ | ||
allowOffset?: boolean | null; | ||
/** Require a certain sub-second precision on the date. (default: null -- any or no sub-second precision) */ | ||
precision?: number | null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
i'd have both of these options not be nullable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Done!
yes open to this 👍 |
@jquense Just a heads up that I believe I have addressed both of your comments! |
@0livare sorry this is taking so long but can you fix the build? |
This will allow us to reuse the date struct for .datetime()
undefined is now the default value for precision, which I think makessense because it indicates that the precision is "not defined", andtherefore can have any or zero digits of precision.
0livare commentedFeb 14, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@jquense build is fixed! (no changes, I just rebased onto the latest master) |
thanks! |
Uh oh!
There was an error while loading.Please reload this page.
yup.date()
always attempts to parse input into aDate
object. Sometimes that is undesirable and you just want the string to be left alone. Currently yup does not have a solution for that use case, but that's where.datetime()
comes in!With an API inspired byzod.datetime,
datetime
also provides greater control over the exact required format of the ISO string thandate
does.