Find a file
2026-04-17 19:19:35 -04:00
.github/workflows chore(deps): update actions/checkout action to v4 2024-11-15 11:34:15 -08:00
src fix: add year bounds check to schedule iteration, refactor next_after/prev_from 2026-04-17 19:19:35 -04:00
tests fix: add year bounds check to schedule iteration, refactor next_after/prev_from 2026-04-17 19:19:35 -04:00
.gitignore rustfmt 2017-02-27 18:43:10 -05:00
Cargo.toml fix: add year bounds check to schedule iteration, refactor next_after/prev_from 2026-04-17 19:19:35 -04:00
CHANGELOG.md fix: add year bounds check to schedule iteration, refactor next_after/prev_from 2026-04-17 19:19:35 -04:00
LICENSE-APACHE MIT/Apache-2.0 dual license 2021-02-24 19:56:56 -05:00
LICENSE-MIT MIT/Apache-2.0 dual license 2021-02-24 19:56:56 -05:00
README.md fix: add year bounds check to schedule iteration, refactor next_after/prev_from 2026-04-17 19:19:35 -04:00
release.toml feat: configure cargo-release 2025-01-16 19:06:40 +01:00
renovate.json Add renovate.json 2024-11-15 20:29:01 +01:00
rustfmt.toml provide rustfmt.toml (#4) 2024-11-01 09:56:14 -07:00

jiff-cron Rust dependency status

NOTE: these are temporary releases while waiting for the original repo to release their 0.2.0.

A cron expression parser built with jiff.

Examples

use jiff_cron::{
    jiff::tz::TimeZone,
    Schedule,
};
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(TimeZone::UTC).take(10) {
      println!("-> {}", datetime);
    }
}

/*
Upcoming fire times:
-> 2018-06-01T09:30:00+00:00[UTC]
-> 2018-06-01T12:30:00+00:00[UTC]
-> 2018-06-01T15:30:00+00:00[UTC]
-> 2018-06-15T09:30:00+00:00[UTC]
-> 2018-06-15T12:30:00+00:00[UTC]
-> 2018-06-15T15:30:00+00:00[UTC]
-> 2018-08-01T09:30:00+00:00[UTC]
-> 2018-08-01T12:30:00+00:00[UTC]
-> 2018-08-01T15:30:00+00:00[UTC]
-> 2018-08-15T09:30:00+00:00[UTC]
*/

DST behavior

jiff also handles daylight savings gaps and folding appropriately:

use jiff_cron::{
    jiff::tz::TimeZone,
    jiff::civil::date,
    Schedule,
};
use std::str::FromStr;

fn main() {
    let expression = "0 0 * * * * *";
    let schedule = Schedule::from_str(expression).unwrap();
    let after_datetime = date(2022, 11, 5).at(23, 30, 0, 0).in_tz("America/Chicago").unwrap();
    println!("Upcoming fire times:");
    for datetime in schedule.after(&after_datetime).take(5) {
      println!("-> {}", datetime);
    }
}

/*
Upcoming fire times:
-> 2022-11-06T00:00:00-05:00[America/Chicago]
-> 2022-11-06T01:00:00-05:00[America/Chicago]
-> 2022-11-06T01:00:00-06:00[America/Chicago]
-> 2022-11-06T02:00:00-06:00[America/Chicago]
-> 2022-11-06T03:00:00-06:00[America/Chicago]
*/

Installation

Add to your Cargo.toml:

jiff-cron = "0.2.1"

You can enable optional serde support via crate feature toggle.

License

Licensed under either of

Minimum supported Rust version (MSRV)

This crate requires Rust 1.80.0 or newer.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.