diff --git a/inquire/src/prompts/dateselect/prompt.rs b/inquire/src/prompts/dateselect/prompt.rs index cf968710..70543b0f 100644 --- a/inquire/src/prompts/dateselect/prompt.rs +++ b/inquire/src/prompts/dateselect/prompt.rs @@ -145,10 +145,22 @@ where fn handle(&mut self, action: DateSelectPromptAction) -> InquireResult { let result = match action { - DateSelectPromptAction::GoToPrevWeek => self.shift_date(Duration::weeks(-1)), - DateSelectPromptAction::GoToNextWeek => self.shift_date(Duration::weeks(1)), - DateSelectPromptAction::GoToPrevDay => self.shift_date(Duration::days(-1)), - DateSelectPromptAction::GoToNextDay => self.shift_date(Duration::days(1)), + DateSelectPromptAction::GoToPrevWeek => self.shift_date( + Duration::try_weeks(-1) + .expect("unexpected overflow when calculating duration of 1 week"), + ), + DateSelectPromptAction::GoToNextWeek => self.shift_date( + Duration::try_weeks(1) + .expect("unexpected overflow when calculating duration of 1 week"), + ), + DateSelectPromptAction::GoToPrevDay => self.shift_date( + Duration::try_days(-1) + .expect("unexpected overflow when calculating duration of 1 day"), + ), + DateSelectPromptAction::GoToNextDay => self.shift_date( + Duration::try_days(1) + .expect("unexpected overflow when calculating duration of 1 day"), + ), DateSelectPromptAction::GoToPrevYear => self.shift_months(-12), DateSelectPromptAction::GoToNextYear => self.shift_months(12), DateSelectPromptAction::GoToPrevMonth => self.shift_months(-1), diff --git a/inquire/src/ui/backend.rs b/inquire/src/ui/backend.rs index e84c7596..a6baf917 100644 --- a/inquire/src/ui/backend.rs +++ b/inquire/src/ui/backend.rs @@ -542,7 +542,9 @@ pub mod date { let mut date_it = get_start_date(month, year); // first date of week-line is possibly in the previous month if date_it.weekday() == week_start { - date_it = date_it.sub(Duration::weeks(1)); + date_it = date_it.sub( + Duration::try_weeks(1).expect("overflow when calculating duration of 1 week"), + ); } else { while date_it.weekday() != week_start { date_it = match date_it.pred_opt() { diff --git a/inquire/src/utils.rs b/inquire/src/utils.rs index d366d033..61d8b9d4 100644 --- a/inquire/src/utils.rs +++ b/inquire/src/utils.rs @@ -84,6 +84,18 @@ where len } +impl<'a, T> Debug for Page<'a, T> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Page") + .field("first", &self.first) + .field("last", &self.last) + .field("content", &format!("({} elements)", &self.content.len())) + .field("cursor", &self.cursor) + .field("total", &self.total) + .finish() + } +} + #[cfg(test)] mod test { #![allow(clippy::bool_assert_comparison)] @@ -249,15 +261,3 @@ mod test { assert_eq!(6, page.total); } } - -impl<'a, T> Debug for Page<'a, T> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("Page") - .field("first", &self.first) - .field("last", &self.last) - .field("content", &format!("({} elements)", &self.content.len())) - .field("cursor", &self.cursor) - .field("total", &self.total) - .finish() - } -}