Expand description
Library for parsing cron expressions with timezone support.
Example:
use chrono::{TimeZone, Utc};
use chrono_tz::Europe::Lisbon;
use cron_parser::parse;
if let Ok(next) = parse("*/5 * * * *", &Utc::now()) {
println!("when: {}", next);
}
// every 6 hours starting at 1:00
if let Ok(next) = parse("0 1/6 * * *", &Utc::now()) {
println!("when: {}", next);
}
// passing a custom timestamp
if let Ok(next) = parse("0 0 29 2 *", &Utc.timestamp_opt(1893456000, 0).unwrap()) {
println!("next leap year: {}", next);
assert_eq!(next.timestamp(), 1961625600);
}
assert!(parse("2-3,9,*/15,1-8,11,9,4,5 * * * *", &Utc::now()).is_ok());
assert!(parse("* * * * */Fri", &Utc::now()).is_err());
// use custom timezone
assert!(parse("*/5 * * * *", &Utc::now().with_timezone(&Lisbon)).is_ok());
Enums§
Functions§
- parse
- Parse cron expression
- parse_
field parse_field
Allowed special characters: