tpt-cron-parse
Cron expression parser with precise error reporting and human-readable output. No dependencies.
Supports standard 5-field and extended 6-field (with seconds) cron syntax.
Features
- 5-field (
min hour dom month dow) and 6-field (sec min hour dom month dow) cron - Precise errors —
CronErrorincludes the byte position, which field failed, what was expected, and what was found - Human-readable —
to_human_readable()converts expressions to English - No dependencies — pure Rust
Usage
use CronExpr;
let expr = parse.unwrap;
println!; // Every Monday at 9:00 AM
let expr = parse.unwrap;
println!; // Every 5 minutes
Error Reporting
use CronExpr;
let err = parse.unwrap_err;
println!; // cron parse error in minutes field at position 0: expected digit, found 'x'
Human-Readable Examples
| Expression | Output |
|---|---|
* * * * * |
Every minute |
0 * * * * |
Every hour |
0 9 * * * |
Every day at 9:00 AM |
0 9 * * 1 |
Every Monday at 9:00 AM |
0 9 1 * * |
At 9:00 AM on the 1st of every month |
*/5 * * * * |
Every 5 minutes |
0 0 1 1 * |
At 12:00 AM on January 1st |
Computing the next run time
The crate stays dependency-free by default. Enable the optional chrono feature
to compute the next firing time of a schedule:
[]
= { = "0.1", = ["chrono"] }
use CronExpr;
use ;
let expr = parse.unwrap;
let after = Utc.with_ymd_and_hms.unwrap; // Monday
let next = expr.next_after.unwrap; // next weekday at 09:00
next_after respects the standard cron day-of-month / day-of-week OR rule and
searches at most ~4 years ahead (the maximum period of a cron schedule).
License
Licensed under either of Apache License 2.0 or MIT at your option.