TimeRange#

One interval of working hours within a day. A calendar's daily hours are a list of these ranges: Worktime::hours for the regular week and DayRule::Hours for a date exception. There's no constructor; build it with a struct literal.

Declaration#

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct TimeRange {
    pub start: u16,
    pub end: u16,
}

Fields#

start#

pub start: u16

Start of the range in minutes since midnight. Valid values are 0 to 1439 (00:00 to 23:59).

end#

pub end: u16

End of the range in minutes since midnight. Valid values are 0 to 1440; 1440 is 24:00.

When end is less than or equal to start, the range crosses midnight: it runs from start to end on the next day and belongs to the day it starts on. { start: 1320, end: 360 } is 22:00 to 06:00. When end equals start, the range covers 24 hours.

A start of 1440 or more, or an end above 1440, fails validation of the ProjectData that holds the calendar. The error is an InputError of kind Validation, with the message hour range must be within 00:00..24:00 and a path such as calendars[0].worktime.hours or calendars[0].worktime.dates[2026-08-14].

Example#

A calendar with a night shift from 22:00 to 06:00:

use plen_core::{CalendarData, TimeRange, Worktime};

fn main() {
    let night = CalendarData {
        id: "night".into(),
        worktime: Some(Worktime {
            hours: Some(vec![TimeRange {
                start: 22 * 60,
                end: 6 * 60,
            }]),
            ..Default::default()
        }),
    };
    println!("{night:?}");
}