#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

#17 in Date and time

Download history 16/week @ 2018-06-22 92/week @ 2018-06-29 10/week @ 2018-07-06 15/week @ 2018-07-13 52/week @ 2018-07-20 67/week @ 2018-07-27 48/week @ 2018-08-03 118/week @ 2018-08-10 27/week @ 2018-08-17 46/week @ 2018-08-24 40/week @ 2018-08-31 68/week @ 2018-09-07 70/week @ 2018-09-14

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

~1.5MB
~26K SLoC