workclock 0.1.2

Business-time arithmetic over working hours, breaks, holidays and time zones, including overnight shifts
Documentation

workclock

Fast, correct business-time arithmetic (working hours, SLAs, shifts) for Rust, with Python and JavaScript bindings.

  • How much working time lies between two datetimes?
  • What datetime do you reach after adding or subtracting N working hours?
cargo add workclock jiff

The API takes and returns jiff 0.2 types.

use jiff::civil::time;
use jiff::{SignedDuration, Timestamp};
use workclock::{Schedule, Weekdays, WorkDay};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let schedule = Schedule::builder()
        .rule(WorkDay::new(time(22, 0, 0, 0), time(6, 0, 0, 0), Weekdays::MON_TO_FRI))
        .build()?;

    let monday_night: Timestamp = "2026-01-05T22:00:00Z".parse()?;
    let tuesday_morning: Timestamp = "2026-01-06T06:00:00Z".parse()?;
    assert_eq!(schedule.between(monday_night, tuesday_morning), SignedDuration::from_hours(8));
    assert_eq!(
        schedule.add(monday_night, SignedDuration::from_hours(4))?.to_string(),
        "2026-01-06T02:00:00Z",
    );
    Ok(())
}

API documentation is on docs.rs, and the repository has the specification and the Python and JavaScript bindings. Licensed under MIT.