From ee088d51843735cbd78af714b262a0807ab6e259 Mon Sep 17 00:00:00 2001 From: Mauro D Date: Sun, 29 Oct 2023 20:42:36 +0100 Subject: [PATCH] Fixed cron issue handling DST --- crates/utils/src/config/cron.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/utils/src/config/cron.rs b/crates/utils/src/config/cron.rs index 31a581af..a92ba936 100644 --- a/crates/utils/src/config/cron.rs +++ b/crates/utils/src/config/cron.rs @@ -41,7 +41,8 @@ impl SimpleCron { SimpleCron::Day { hour, minute } => { let next = chrono::Local .with_ymd_and_hms(now.year(), now.month(), now.day(), *hour, *minute, 0) - .unwrap(); + .earliest() + .unwrap_or_else(|| now - chrono::Duration::seconds(1)); if next < now { next + chrono::Duration::days(1) } else { @@ -51,7 +52,8 @@ impl SimpleCron { SimpleCron::Week { day, hour, minute } => { let next = chrono::Local .with_ymd_and_hms(now.year(), now.month(), now.day(), *hour, *minute, 0) - .unwrap(); + .earliest() + .unwrap_or_else(|| now - chrono::Duration::seconds(1)); if next < now { next + chrono::Duration::days( (7 - now.weekday().number_from_monday() + *day).into(), @@ -63,7 +65,8 @@ impl SimpleCron { SimpleCron::Hour { minute } => { let next = chrono::Local .with_ymd_and_hms(now.year(), now.month(), now.day(), now.hour(), *minute, 0) - .unwrap(); + .earliest() + .unwrap_or_else(|| now - chrono::Duration::seconds(1)); if next < now { next + chrono::Duration::hours(1) } else {