-
Notifications
You must be signed in to change notification settings - Fork 533
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
Convert NaiveDate/NaiveDateTime::checked_(add/sub)_days
to return Result
#1475
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## 0.5.x #1475 +/- ##
==========================================
- Coverage 94.02% 94.02% -0.01%
==========================================
Files 37 37
Lines 16974 16954 -20
==========================================
- Hits 15960 15941 -19
+ Misses 1014 1013 -1 ☔ View full report in Codecov by Sentry. |
Thanks for the feedback, I will take it into account. Just haven't found time so far. |
Thank you for the update. There is no hurry. |
/// NaiveDate::from_ymd(2022, 7, 31).unwrap().checked_add_days(Days::new(2)), | ||
/// Some(NaiveDate::from_ymd(2022, 8, 2).unwrap()) | ||
/// NaiveDate::from_ymd(2022, 2, 20)?.checked_add_days(Days::new(9)), | ||
/// NaiveDate::from_ymd(2022, 3, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a more interesting example 👍.
@@ -1999,7 +1993,7 @@ impl Iterator for NaiveDateWeeksIterator { | |||
|
|||
fn next(&mut self) -> Option<Self::Item> { | |||
let current = self.value; | |||
self.value = current.checked_add_days(Days::new(7))?; | |||
self.value = current.checked_add_days(Days::new(7)).ok()?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to this PR, so just ignore this comment.
I wonder if the NaiveDateWeeksIterator
can cover the complete range of NaiveDate
, or if it fails one week before the end.
Thank you! |
This pull request targets the issue #1469.
try_opt_ok
macro to simplify unwrappingResult
in anOption
contexttry_add
macro to improve handling ofi32::checked_add()
Result
:naive
module #1445NaiveDate/NaiveDateTime::checked_(add/sub)_days
to returnResult
cc @pitdicker