feat(string): Create .datetime() - #2087
Merged
Merged
Conversation
Contributor
Author
|
@jquense is this something you would consider? |
jquense
reviewed
Sep 29, 2023
|
|
||
| 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)_ |
Contributor
Author
There was a problem hiding this comment.
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.
jquense
reviewed
Sep 29, 2023
| /** 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; |
Owner
There was a problem hiding this comment.
i'd have both of these options not be nullable
Owner
|
yes open to this 👍 |
Contributor
Author
|
@jquense Just a heads up that I believe I have addressed both of your comments! |
jquense
approved these changes
Feb 1, 2024
Owner
|
@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 makes sense because it indicates that the precision is "not defined", and therefore can have any or zero digits of precision.
Contributor
Author
|
@jquense build is fixed! (no changes, I just rebased onto the latest master) |
jquense
approved these changes
Feb 28, 2024
Owner
|
thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
yup.date()always attempts to parse input into aDateobject. 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 by zod.datetime,
datetimealso provides greater control over the exact required format of the ISO string thandatedoes.