Crate office_hours

source ·
Expand description

Give your code a break like any good employer!

Are you tired of your code working all day every day? Don’t you feel bad that your code keeps working while you’re off relaxing and having fun after work?

Well now you can use the power of office-hours to only run your code within the working hours of the day!

Important

At the time of writing, the office hours are determined from the Local Time Zone of the host machine where the code is running. I might consider updating this library to support other timezones if I really want to suffer :P

Quick Start

use chrono::Timelike;
use office_hours::{Clock, OfficeHours};

// 9am to 5pm are the default office hours
let office_hours = OfficeHours::default();
if office_hours.now() {
    println!("Blimey! Is it time for work already?");
} else {
    println!("Phew, still on break!");
}

// 12pm to 5pm
let afternoon = OfficeHours::new(Clock::TwelvePm, Clock::FivePm);
if afternoon.now() {
    println!("Blimey! Is it time for work already?");
} else {
    println!("Phew, still on break!");
}

// We can also cross the day boundary - 10pm to 6am
let night_shift = OfficeHours::new(Clock::TenPm, Clock::SixAm);
if night_shift.now() {
    println!("Blimey! Is it time for work already?");
} else {
    println!("Phew, still on break!");
}

// Iterate over office hours as chrono::NaiveTime
for time in office_hours.iter() {
    println!("Hour: {:?}", time.hour());
    println!("Minute: {:?}", time.minute());
    println!("Second: {:?}", time.second());
}

// Iterate over office hours as u32
for hour in office_hours.hours_iter() {
    println!("Hour: {:?}", hour);
}

Macros

  • Creates an OfficeHours that takes in a list of statements to execute when the current time is between office hours.

Structs

Enums

Traits