oxedyne/fe2o3/fe2o3_datime/tests/cron.rs
1.4 KiB, 1 run
created by r1870400018:79756, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | use oxedyne_fe2o3_core::prelude::*; |
| 2 | use oxedyne_fe2o3_datime::{ |
| 3 | schedule::recurrence::CronExpression, |
| 4 | time::{ |
| 5 | CalClock, |
| 6 | CalClockZone, |
| 7 | }, |
| 8 | }; |
| 9 | |
| 10 | // The next time `line` names after 10:00 on Tuesday 17 November 2026, as (month, day, hour). |
| 11 | fn next(line: &str) -> Outcome<(u8, u8, u8)> { |
| 12 | let from = res!(CalClock::new(2026, 11, 17, 10, 0, 0, 0, CalClockZone::utc())); |
| 13 | let c = res!(res!(res!(CronExpression::parse(line)).next_execution(&from)) |
| 14 | .ok_or_else(|| err!("No next time for {:?}.", line; Missing))); |
| 15 | Ok((c.month(), c.day(), c.hour())) |
| 16 | } |
| 17 | |
| 18 | #[test] |
| 19 | fn test_a_day_of_the_month_and_a_weekday_both_named_match_either_as_cron_does() -> Outcome<()> { |
| 20 | // The 13th or a Friday: Friday the 20th comes first. |
| 21 | assert_eq!(res!(next("0 9 13 * 5")), (11, 20, 9)); |
| 22 | // The 20th or a Monday: the 20th, a Friday, comes before Monday the 23rd. |
| 23 | assert_eq!(res!(next("0 9 20 * 1")), (11, 20, 9)); |
| 24 | // The 18th or a Friday: Wednesday the 18th. |
| 25 | assert_eq!(res!(next("0 9 18 * 5")), (11, 18, 9)); |
| 26 | Ok(()) |
| 27 | } |
| 28 | |
| 29 | #[test] |
| 30 | fn test_a_day_left_starred_restricts_by_the_other_alone() -> Outcome<()> { |
| 31 | assert_eq!(res!(next("0 9 * * 5")), (11, 20, 9), "Fridays only"); |
| 32 | assert_eq!(res!(next("0 9 13 * *")), (12, 13, 9), "the 13th only"); |
| 33 | assert_eq!(res!(next("0 9 */1 * 1")), (11, 23, 9), "a step from * leaves the day of the month unrestricted"); |
| 34 | assert_eq!(res!(next("30 * * * *")), (11, 17, 10), "every hour at half past"); |
| 35 | Ok(()) |
| 36 | } |