Skip to content

Commit 9acd373

Browse files
author
bconn98
committed
chore: unwrap safe try_days call
1 parent ef197e5 commit 9acd373

File tree

1 file changed

+6
-5
lines changed
  • src/append/rolling_file/policy/compound/trigger

1 file changed

+6
-5
lines changed

src/append/rolling_file/policy/compound/trigger/time.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,15 @@ impl TimeTrigger {
247247
let day = current.day();
248248
if let TimeTriggerInterval::Week(n) = interval {
249249
let week0 = current.iso_week().week0() as i64;
250-
let weekday = current.weekday().num_days_from_monday() as i64; // Monday is the first day of the week
251250
let time = Local.with_ymd_and_hms(year, month, day, 0, 0, 0).unwrap();
252251
let increment = if modulate { n - week0 % n } else { n };
252+
253+
// Unwrap instead of propogate the try_days call as this is a known safe value
254+
// generated by the chrono library as a value between 0-6.
255+
let weekday = current.weekday().num_days_from_monday() as i64; // Monday is the first day of the week
253256
let dur = Duration::try_weeks(increment).ok_or(
254257
TimeTriggerIntervalError::OutOfBounds("Weeks".to_owned(), interval),
255-
)? - Duration::try_days(weekday).ok_or(
256-
TimeTriggerIntervalError::OutOfBounds("Days".to_owned(), interval),
257-
)?;
258+
)? - Duration::try_days(weekday).unwrap();
258259
return Ok(time + dur);
259260
}
260261

@@ -527,7 +528,7 @@ mod test {
527528
}
528529

529530
#[test]
530-
fn test_err() {
531+
fn test_days_overflow() {
531532
let config = TimeTriggerConfig {
532533
interval: TimeTriggerInterval::Day(i64::MAX),
533534
modulate: false,

0 commit comments

Comments
 (0)