sablier_cron/lib.rs
1#![deny(rust_2018_idioms)]
2
3//! A cron expression parser and schedule explorer
4//! # Example
5//! ```
6//! use sablier_cron::Schedule;
7//! use chrono::{DateTime, NaiveDateTime, Utc};
8//! use std::str::FromStr;
9//!
10//! // sec min hour day of month month day of week year
11//! let expression = "0 30 9,12,15 1,15 May-Aug Mon,Wed,Fri 2018/2";
12//! let schedule = Schedule::from_str(expression).unwrap();
13//! let ts = 1234567890;
14//! let next_ts = match schedule
15//! .after(&DateTime::<Utc>::from_utc(
16//! NaiveDateTime::from_timestamp(ts, 0),
17//! Utc,
18//! ))
19//! .take(1)
20//! .next()
21//! {
22//! Some(datetime) => Some(datetime.timestamp()),
23//! None => None,
24//! };
25//!
26//! /*
27//! Upcoming fire times:
28//! -> 2018-06-01 09:30:00 UTC
29//! -> 2018-06-01 12:30:00 UTC
30//! -> 2018-06-01 15:30:00 UTC
31//! -> 2018-06-15 09:30:00 UTC
32//! -> 2018-06-15 12:30:00 UTC
33//! -> 2018-06-15 15:30:00 UTC
34//! -> 2018-08-01 09:30:00 UTC
35//! -> 2018-08-01 12:30:00 UTC
36//! -> 2018-08-01 15:30:00 UTC
37//! -> 2018-08-15 09:30:00 UTC
38//! */
39//! ```
40
41pub mod error;
42mod ordinal;
43mod parsing;
44mod queries;
45mod schedule;
46mod specifier;
47mod time_unit;
48
49pub use crate::schedule::Schedule;
50pub use crate::time_unit::TimeUnitSpec;