convenience functions to create NaiveDates#893
Conversation
bbe5709 to
bff51bd
Compare
jtmoon79
left a comment
There was a problem hiding this comment.
These look convenient!
Please add #[must_use] to these functions.
|
I am not super convinced of the usefulness of all these methods. My reason is that there are all kinds of operations someone may want to do on dates. Where do you draw the line?
But then you would also want Would similar methods on |
| Self::from_ymd_opt(year.into(), month.number_from_month(), 1).unwrap() | ||
| } | ||
|
|
||
| /// Create a `NaiveDate` of the ;ast day of the given year and month |
There was a problem hiding this comment.
| /// Create a `NaiveDate` of the ;ast day of the given year and month | |
| /// Create a `NaiveDate` of the last day of the given year and month |
| /// | ||
| /// This takes an `i16` rather than `i32` to ensure it is not | ||
| /// out of the allowed range | ||
| pub fn start_year(year: i16) -> NaiveDate { |
There was a problem hiding this comment.
Using an i16 ties into your work in #882. But maybe it is best to accept an i32 until the decision is made to restrict the range of allowed years?
| /// out of the allowed range | ||
| pub fn end_year(year: i16) -> NaiveDate { | ||
| // ideally this unwrap can be later removed | ||
| Self::from_ymd_opt(i32::from(year) + 1, 1, 1).unwrap().pred_opt().unwrap() |
There was a problem hiding this comment.
This might fail if year == MAX_YEAR.
| // ideally this unwrap can be later removed | ||
| let start = Self::start_month(year, month); | ||
|
|
||
| (start + Months::new(1)).pred_opt().unwrap() |
There was a problem hiding this comment.
This might fail if year == MAX_YEAR && month == 12.
|
Closing. I would be interested to have a method to easily create a |
These functions are to reduce the number of unwraps needed when creating NaiveDates