-
Notifications
You must be signed in to change notification settings - Fork 534
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
Missing method to initialize a DateTime
with non-zero millis or nanos
#873
Comments
Yes, the recommended way to do this is something like (I think the deprecation message was trying to point you in this direction?) |
Thanks your solution is ok but maybe too verbose? there is a specific reason to deprecate |
NaiveDateTime::from_ymd_opt(2022, 11, 14)?.and_hms_milli_opt(23, 59, 59, 999)?.and_local_timezone(Utc)? is only slightly more verbose than Utc.ymd_opt(2022, 11, 14)?.and_hms_milli_opt(23, 59, 59, 999)? but has an added advantage that you don't need to import the However I'm keen to understand occurrence of usages like this in code bases to see where we can possibly improve the API. From my own experience in codebases, I'm thinking of the following:
Would these and/or similar methods assist in reducing the total amount of verbosity? |
(We wouldn't want to implement |
I'm trying out some ideas extending #845 where the year part of the date is infallible, but represented by a i16. IMO reducing the year range, but having it be infallible could be an excellent tradeoff if it opens up the possibilities mentioned above |
I think this would be a lot easier if something like |
Yeah, that tradeoff definitely makes a lot of sense!
Anything that has more than one |
Came up against this recently, and there isn't really a pretty way around it. In the end I used Would be really nice to be able to just specify all components at once. How about somthing like |
@eilidh-spire do any of the solutions proposed in #815 look ok? These could be extended as you describe with a milliseconds parameter as well |
@esheppa thanks for linking, I'm all for fallible constructors being the default - much better to have the compiler make us handle erroneous input, and even if we just unwrap at the end of the day, it at least makes the possible panic explicit. We're mostly using these functions to construct UTC dates in test code, so the main concern is really being succinct and readable - a li'l |
Trying to upgrade to 0.4.23 I'm facing a limitation of the trait
TimeZone
where now the only way to get a DateTime is viawith_ymd_and_hms
that assume nanos always 0.I think that the trait should expose a method to override this behaviour or
ymd_opt
shouldn't be deprecated, in particular my usecase is something like:I'm missing a way to do this?
The text was updated successfully, but these errors were encountered: