#cron #schedule #repeat #periodic #time

cron

A cron expression parser and schedule explorer

9 releases (breaking)

0.6.0 Aug 8, 2018
0.5.0 Aug 6, 2018
0.4.1 Jun 1, 2018
0.4.0 Aug 4, 2017
0.0.2 Jun 27, 2015

#18 in Date and time

Download history 75/week @ 2018-10-23 103/week @ 2018-10-30 205/week @ 2018-11-06 102/week @ 2018-11-13 149/week @ 2018-11-20 77/week @ 2018-11-27 126/week @ 2018-12-04 77/week @ 2018-12-11 91/week @ 2018-12-18 88/week @ 2018-12-25 59/week @ 2019-01-01 52/week @ 2019-01-08 37/week @ 2019-01-15

210 downloads per month
Used in 2 crates

MIT license

40KB
1K SLoC

cron

A Cron Expression Parser in Rust

extern crate cron;
extern crate chrono;

use cron::Schedule;
use chrono::Utc;
use std::str::FromStr;

fn main() {
  //               sec  min   hour   day of month   month   day of week   year
  let expression = "0   30   9,12,15     1,15       May-Aug  Mon,Wed,Fri  2018/2";
  let schedule = Schedule::from_str(expression).unwrap();
  println!("Upcoming fire times:");
  for datetime in schedule.upcoming(Utc).take(10) {
    println!("-> {}", datetime);
  }
}

/*
Upcoming fire times:
-> 2018-06-01 09:30:00 UTC
-> 2018-06-01 12:30:00 UTC
-> 2018-06-01 15:30:00 UTC
-> 2018-06-15 09:30:00 UTC
-> 2018-06-15 12:30:00 UTC
-> 2018-06-15 15:30:00 UTC
-> 2018-08-01 09:30:00 UTC
-> 2018-08-01 12:30:00 UTC
-> 2018-08-01 15:30:00 UTC
-> 2018-08-15 09:30:00 UTC
*/

lib.rs:

A cron expression parser and schedule explorer

Example

extern crate chrono;
extern crate cron;

use cron::Schedule;
use chrono::Utc;
use std::str::FromStr;

fn main() {
  //               sec  min   hour   day of month   month   day of week   year
  let expression = "0   30   9,12,15     1,15       May-Aug  Mon,Wed,Fri  2018/2";
  let schedule = Schedule::from_str(expression).unwrap();
  println!("Upcoming fire times:");
  for datetime in schedule.upcoming(Utc).take(10) {
    println!("-> {}", datetime);
  }
}

/*
Upcoming fire times:
-> 2018-06-01 09:30:00 UTC
-> 2018-06-01 12:30:00 UTC
-> 2018-06-01 15:30:00 UTC
-> 2018-06-15 09:30:00 UTC
-> 2018-06-15 12:30:00 UTC
-> 2018-06-15 15:30:00 UTC
-> 2018-08-01 09:30:00 UTC
-> 2018-08-01 12:30:00 UTC
-> 2018-08-01 15:30:00 UTC
-> 2018-08-15 09:30:00 UTC
*/

Dependencies

~2MB
~28K SLoC