From eb9a7bd8dd95b13c2dc420fb9207bdaa06fb6308 Mon Sep 17 00:00:00 2001 From: Dirreke Date: Sun, 10 Mar 2024 00:22:23 +0800 Subject: [PATCH] Update time.rs --- .../rolling_file/policy/compound/trigger/time.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/append/rolling_file/policy/compound/trigger/time.rs b/src/append/rolling_file/policy/compound/trigger/time.rs index ffad356f..16235ed9 100644 --- a/src/append/rolling_file/policy/compound/trigger/time.rs +++ b/src/append/rolling_file/policy/compound/trigger/time.rs @@ -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(); @@ -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(); @@ -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(); @@ -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!"); } @@ -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 };