Rust

Undocumented.

Contents

use utopia_schedule::Cron;
Rust
pub struct Cron

A 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:

FieldSyntaxMeaning
either?no specific value, same as *
day of monthLlast day of the month
day of monthL-3three days before the last day
day of monthLWlast weekday of the month
day of month15Wweekday nearest the 15th, never crossing the month
day of week5Llast Friday of the month
day of weekFRI#3third 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");