cron
ModuleUndocumented.
Contents
use utopia_schedule::Cron;Rust
pub struct CronA recurring trigger described by a five-field cron expression: minute, hour, day of month, month, day of week.
The portable cron core is supported: *, values, ranges (a-b), steps
(every n-th value over * or a range, a-b/n), lists (,), month and
day names (JAN, FRI), 7 as Sunday, and the @hourly … @yearly
macros. Following vixie cron, a day matches when either day field hits
if both day-of-month and day-of-week are restricted, and both
otherwise.
The Quartz extensions to the two day fields are supported too, also inside a list alongside plain values:
| Field | Syntax | Meaning |
|---|---|---|
| either | ? | no specific value, same as * |
| day of month | L | last day of the month |
| day of month | L-3 | three days before the last day |
| day of month | LW | last weekday of the month |
| day of month | 15W | weekday nearest the 15th, never crossing the month |
| day of week | 5L | last Friday of the month |
| day of week | FRI#3 | third Friday of the month |
Rust
use php_std::datetime::{DateTime, Timestamp, TzInfo};
use utopia_schedule::{Cron, Trigger};
let at = |s: &str| DateTime::parse(s.as_bytes(), None, &TzInfo::utc(), Timestamp { sec: 0, usec: 0 }).unwrap();
let cron = Cron::new("15,45-50/2 8 * * *")?;
let due = cron.occurrences_between(&at("2026-08-17 00:00:00"), &at("2026-08-18 00:00:00"));
let due: Vec<_> = due.iter().map(|d| String::from_utf8(d.format(b"H:i")).unwrap()).collect();
assert_eq!(due, ["08:15", "08:45", "08:47", "08:49"]);
assert_eq!(Cron::new("0 0 31 2 *").unwrap_err().to_string(), "Cron expression \"0 0 31 2 *\" never matches a date");