Handle Daylight Saving Time (DST) transitions with Schedule
masterThe Schedule iterator correctly handles ambiguous or non-existent times caused by Daylight Saving Time transitions. When using after(&dt) or nth_back(n), the library ensures that it does not panic when encountering times that fall within a DST gap or overlap.
For example, in a timezone like America/Chicago, an hourly schedule will correctly yield both instances of an hour that repeats during a fallback transition (e.g., 1 AM CDT followed by 1 AM CST).
use chrono_tz::Tz;
use cron::Schedule;
let schedule_tz: Tz = "America/Chicago".parse().unwrap();
let dt = schedule_tz.with_ymd_and_hms(2022, 11, 5, 23, 30, 0).unwrap();
let schedule = Schedule::from_str("0 0 * * * * *").unwrap();
// Iterating forward through a DST transition
let times = schedule
.after(&dt)
.map(|x| x.to_string())
.take(5)
.collect::<Vec<_>>();
// Expected behavior includes the repeated hour during fallback
// ["2022-11-06 00:00:00 CDT", "2022-11-06 01:00:00 CDT", "2022-11-06 01:00:00 CST", ...]