cron_clock/
lib.rs

1#![deny(rust_2018_idioms)]
2#![allow(clippy::derive_hash_xor_eq)]
3#![allow(broken_intra_doc_links)]
4
5//! A cron expression parser and schedule explorer.
6//!
7//! In addition to the regular expressions, you can also use the following shortcut expressions with Schedule::from_str,
8//! such as `@yearly` `@monthly` `@weekly` `@daily` `@hourly` `@minutely` `@secondly`,
9//! make cron- Expression Iterator.
10//!
11//!
12//! ## Tips  
13//! If you need a periodicized task manager, you may need [`delay-timer`](https://github.com/BinChengZhao/delay-timer)
14//! (Time-manager of delayed tasks. Like crontab, but synchronous [`asynchronous`] tasks are possible, and dynamic add/cancel/remove is supported) .
15//!
16//!
17//! # Example
18//! ```
19//!   use cron_clock::Schedule;
20//!   use chrono::Utc;
21//!   use std::str::FromStr;
22//!
23//!   //               sec  min   hour   day of month   month   day of week   year
24//!   let expression = "0   30   9,12,15     1,15       May-Aug  Mon,Wed,Fri  2018/2";
25//!   let schedule = Schedule::from_str(expression).unwrap();
26//!   println!("Upcoming fire times:");
27//!   for datetime in schedule.upcoming(Utc).take(10) {
28//!     println!("-> {}", datetime);
29//!   }
30//!
31//! /*
32//! Upcoming fire times:
33//! -> 2018-06-01 09:30:00 UTC
34//! -> 2018-06-01 12:30:00 UTC
35//! -> 2018-06-01 15:30:00 UTC
36//! -> 2018-06-15 09:30:00 UTC
37//! -> 2018-06-15 12:30:00 UTC
38//! -> 2018-06-15 15:30:00 UTC
39//! -> 2018-08-01 09:30:00 UTC
40//! -> 2018-08-01 12:30:00 UTC
41//! -> 2018-08-01 15:30:00 UTC
42//! -> 2018-08-15 09:30:00 UTC
43//! */
44//! ```
45//!
46//! # Example `shortcut expressions` & `ScheduleIteratorOwned`
47//!
48//! ```
49//! extern crate chrono;
50//! extern crate cron_clock;
51//!
52//! use cron_clock::Schedule;
53//! use chrono::Utc;
54//! use std::str::FromStr;
55//!
56//! fn main() {
57//!   // shortcut expressions
58//!   let expression = "@hourly";
59//!   let schedule = Schedule::from_str(expression).unwrap();
60//!   println!("Upcoming fire times:");
61//!   // `upcoming_owned` Get iterators with ownership, so you don't have lifetime to worry about.
62//!   for datetime in schedule.upcoming_owned(Utc).take(10) {
63//!     println!("-> {}", datetime);
64//!   }
65//! }
66//!
67//! ```
68
69pub mod error;
70
71pub(crate) mod schedule;
72pub(crate) mod time_unit;
73
74mod ordinal;
75mod parsing;
76mod queries;
77mod specifier;
78
79pub use chrono::offset::TimeZone;
80pub use chrono::{FixedOffset, Local, Utc};
81pub use schedule::{Schedule, ScheduleIterator, ScheduleIteratorOwned};
82pub use time_unit::TimeUnitSpec;