#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

#32 in Date and time

Download history 93/week @ 2018-12-20 63/week @ 2018-12-27 42/week @ 2019-01-03 60/week @ 2019-01-10 39/week @ 2019-01-17 56/week @ 2019-01-24 55/week @ 2019-01-31 62/week @ 2019-02-07 48/week @ 2019-02-14 59/week @ 2019-02-21 68/week @ 2019-02-28 93/week @ 2019-03-07 85/week @ 2019-03-14 119/week @ 2019-03-21 83/week @ 2019-03-28

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