-
Notifications
You must be signed in to change notification settings - Fork 508
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
Set year/month/day all at once #549
Comments
If you want to replace two of the three parts of a date, is it not just as easy to create a new date? use chrono::{NaiveDate, Datelike};
let a = NaiveDate::from_ymd(2019, 1, 29);
let b = NaiveDate::from_ymd(2020, 2, 29);
NaiveDate::from_ymd_opt(2020, 2, a.day()); // Some(2020-02-29)
NaiveDate::from_ymd_opt(2019, 1, b.day()); // Some(2019-01-29) This is less tricky to get right. |
At first glance, I'm hesitant to add more API "surface area" for something that is fairly trivial for the user to do. However, the OP makes a good point that there is this not-immediately-obvious "gotcha" that will probably trip-up others. I recommend re-opening this Issue. (My two cents) |
Maybe we should add some documentation to |
My preference is the OPs suggestion but documentation is better than nothing. |
Added some documentation in #1199. |
With the
Datelike
trait, there are methods to return a new date with a different year/month/day. However, these do not provide the ability to easily set more than one of those at once, since the intermediate value might not be valid.e.g.
It would be useful to have a method which applied multiple of these methods at once, without checking for validity of intermediate dates.
The text was updated successfully, but these errors were encountered: