Skip to content

Commit

Permalink
Update time.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirreke committed Mar 9, 2024
1 parent 89f27a7 commit eb9a7bd
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/append/rolling_file/policy/compound/trigger/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,14 @@ impl TimeTrigger {
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 };
return time + Duration::weeks(increment) - Duration::days(weekday);
return time + Duration::try_weeks(increment).expect("The interval of time trigger is too large") - Duration::try_days(weekday).expect("The interval of time trigger is too large");
}

if let TimeTriggerInterval::Day(n) = interval {
let ordinal0 = current.ordinal0() as i64;
let time = Local.with_ymd_and_hms(year, month, day, 0, 0, 0).unwrap();
let increment = if modulate { n - ordinal0 % n } else { n };
return time + Duration::days(increment);
return time + Duration::try_days(increment).expect("The interval of time trigger is too large");
}

let hour = current.hour();
Expand All @@ -238,7 +238,7 @@ impl TimeTrigger {
.with_ymd_and_hms(year, month, day, hour, 0, 0)
.unwrap();
let increment = if modulate { n - (hour as i64) % n } else { n };
return time + Duration::hours(increment);
return time + Duration::try_hours(increment).expect("The interval of time trigger is too large");
}

let min = current.minute();
Expand All @@ -247,7 +247,7 @@ impl TimeTrigger {
.with_ymd_and_hms(year, month, day, hour, min, 0)
.unwrap();
let increment = if modulate { n - (min as i64) % n } else { n };
return time + Duration::minutes(increment);
return time + Duration::try_minutes(increment).expect("The interval of time trigger is too large");
}

let sec = current.second();
Expand All @@ -256,7 +256,7 @@ impl TimeTrigger {
.with_ymd_and_hms(year, month, day, hour, min, sec)
.unwrap();
let increment = if modulate { n - (sec as i64) % n } else { n };
return time + Duration::seconds(increment);
return time + Duration::try_seconds(increment).expect("The interval of time trigger is too large");
}
panic!("Should not reach here!");
}
Expand All @@ -278,7 +278,7 @@ impl TimeTrigger {
let next_time = TimeTrigger::get_next_time(current, self.interval, self.modulate);
let next_roll_time = if self.max_random_delay > 0 {
let random_delay = rand::thread_rng().gen_range(0..self.max_random_delay);
next_time + Duration::seconds(random_delay as i64)
next_time + Duration::try_seconds(random_delay as i64).expect("The max_random_delay of time trigger is too large")
} else {
next_time
};
Expand Down

0 comments on commit eb9a7bd

Please sign in to comment.