Closed phisch closed 1 year ago
I just saw that there is a test that expects this case to panic:
#[test]
#[should_panic]
fn nth_next_occurence_zeroth_occurence_test() {
date!(2023 - 06 - 25).nth_next_occurrence(Weekday::Monday, 0);
}
So this is not a bug but expected behavior. Though I think it would be better to return None
as the zeroth next occurrence instead.
The panicking behavior is documented, and changing the return type is a breaking change.
Both
nth_next_occurrence
andnth_prev_occurrence
return atime::Date
, but internally use a function that returns anOption<Date>
.This example causes a panic:
Why?
This is because nth_next_occurrence returns
Self
instead ofOption<Self>
:while using checked_nth_next_occurence which returns
Option<Self>
:Both functions should return
Option<Self>
.