Skip to content

Commit

Permalink
Fix time after panicking on leap day (#121)
Browse files Browse the repository at this point in the history
* Add a failing test case for leap day
* Fix time after panicking on leap day
  • Loading branch information
messense authored Feb 29, 2024
1 parent 9d54fb7 commit 493e035
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Schedule {
query.reset_day_of_month();
}
let day_of_month_end = days_in_month(month, year);
let day_of_month_range = (Included(day_of_month_start), Included(day_of_month_end));
let day_of_month_range = (Included(day_of_month_start.min(day_of_month_end)), Included(day_of_month_end));

'day_loop: for day_of_month in self
.fields
Expand Down Expand Up @@ -639,6 +639,14 @@ mod test {
assert!(prev < dt); // test is ensuring line above does not panic
}

#[test]
fn test_no_panic_on_leap_day_time_after() {
let dt = chrono::DateTime::parse_from_rfc3339("2024-02-29T10:00:00.000+08:00").unwrap();
let schedule = Schedule::from_str("0 0 0 * * * 2100").unwrap();
let next = schedule.after(&dt).next().unwrap();
assert!(next > dt); // test is ensuring line above does not panic
}

#[test]
fn test_time_unit_spec_equality() {
let schedule_1 = Schedule::from_str("@weekly").unwrap();
Expand Down

0 comments on commit 493e035

Please sign in to comment.