Crate cron_lingo[][src]

This crate allows to parse a cron-like, human-readable expression. The resulting object can be turned into an iterator to compute the next time::OffsetDateTime one at a time.

The basic idea was to strip down the set of features that we know from our favorite implementation of cron in order to keep the results predictable, which may or may not be the case with cron in some situations (e.g. using the step notation “*/2”).


use cron_lingo::Timetable;
use std::str::FromStr;

let expr = "at 9 o'clock on Monday and Friday";
let timetable = Timetable::from_str(expr).unwrap();

Expression syntax

The syntax is quite limited, but intentionally so.

Here are a few examples:

HourWeekday (optional)Week (optional)
at every houron Monday and Tuesdayin odd weeks
at 7 and 8 o’clockon Tuesday, Saturdayin even weeks
at 7, 8 and 16 o’clockon Friday
at 6, 12, 18 o’clock
at 8 o’clockin odd weeks
at 8 o’clockon Wednesdayin the first week of the month
at 8 o’clockon Wednesdayin the second week of the month
at 8 o’clockon Wednesdayin the third week of the month
at 8 o’clockon Wednesday and Sundayin the fourth week of the month

The examples are quite self-explanatory, but the last four may need some clarification: In the final example, next() could return the date of the fourth Wednesday of this month (or the next if the current one is in the past). But only if the fourth Sunday of this month does not predate the fourth Wednesday, which may be the case when the month in question begins on e.g. Friday.

As you can also see in the table above the column “Week” does not depend on the second block “Weekday”. However omitting the Weekday spec. rarely makes sense. The example in row #5 would (assuming now is a Sunday in an even week) return a time::OffsetDateTime for the next seven days … and then put in a break for the following week.


pub use self::timetable::Timetable;