Skip to content

Commit

Permalink
Patterns with future years should not limit the day and month range (#…
Browse files Browse the repository at this point in the history
…116)

* Patterns with future years should not limit the day and month range
* Test does not depend on Utc::now()
  • Loading branch information
AhmedSoliman authored Oct 28, 2024
1 parent e2fb958 commit bc07787
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ impl Schedule {
.range((Included(query.year_lower_bound()), Unbounded))
.cloned()
{
// It's a future year, the current year's range is irrelevant.
if year > after.year() as u32 {
query.reset_month();
query.reset_day_of_month();
}
let month_start = query.month_lower_bound();
if !self.fields.months.ordinals().contains(&month_start) {
query.reset_month();
Expand Down Expand Up @@ -548,6 +553,22 @@ mod test {
assert_eq!(prev2, next2);
}

#[test]
fn test_next_after_past_date_next_year() {
// Schedule after 2021-10-27
let starting_point = Utc
.with_ymd_and_hms(2021, 10, 27, 0, 0, 0)
.unwrap();

// Triggers on 2022-06-01. Note that the month and day are smaller than
// the month and day in `starting_point`.
let expression = format!("0 5 17 1 6 ? 2022");
let schedule = Schedule::from_str(&expression).unwrap();
let next = schedule.next_after(&starting_point);
println!("NEXT AFTER for {} {:?}", expression, next);
assert!(next.is_some());
}

#[test]
fn test_prev_from() {
let expression = "0 5,13,40-42 17 1 Jan *";
Expand Down

0 comments on commit bc07787

Please sign in to comment.