Skip to content

Commit

Permalink
Fixed cron issue handling DST
Browse files Browse the repository at this point in the history
  • Loading branch information
mdecimus committed Oct 29, 2023
1 parent 795ad97 commit ee088d5
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions crates/utils/src/config/cron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(),
Expand All @@ -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 {
Expand Down

0 comments on commit ee088d5

Please sign in to comment.