diff --git a/src/append/rolling_file/policy/compound/trigger/time.rs b/src/append/rolling_file/policy/compound/trigger/time.rs index 337b8e16..4d2f931a 100644 --- a/src/append/rolling_file/policy/compound/trigger/time.rs +++ b/src/append/rolling_file/policy/compound/trigger/time.rs @@ -247,14 +247,15 @@ impl TimeTrigger { let day = current.day(); if let TimeTriggerInterval::Week(n) = interval { let week0 = current.iso_week().week0() as i64; - let weekday = current.weekday().num_days_from_monday() as i64; // Monday is the first day of the week let time = Local.with_ymd_and_hms(year, month, day, 0, 0, 0).unwrap(); let increment = if modulate { n - week0 % n } else { n }; + + // Unwrap instead of propogate the try_days call as this is a known safe value + // generated by the chrono library as a value between 0-6. + let weekday = current.weekday().num_days_from_monday() as i64; // Monday is the first day of the week let dur = Duration::try_weeks(increment).ok_or( TimeTriggerIntervalError::OutOfBounds("Weeks".to_owned(), interval), - )? - Duration::try_days(weekday).ok_or( - TimeTriggerIntervalError::OutOfBounds("Days".to_owned(), interval), - )?; + )? - Duration::try_days(weekday).unwrap(); return Ok(time + dur); } @@ -527,7 +528,7 @@ mod test { } #[test] - fn test_err() { + fn test_days_overflow() { let config = TimeTriggerConfig { interval: TimeTriggerInterval::Day(i64::MAX), modulate: false,