Worktime#
The working time of one calendar: daily hours, working weekdays and per-date exceptions. It's the worktime field of CalendarData. Build it with a struct literal, or start from Worktime::default(), which is the built-in schedule.
Declaration#
Fields#
| Field | Type | Default | Description |
|---|---|---|---|
hours |
Option<Vec<TimeRange>> |
None = 08:00-12:00, 13:00-17:00 |
Working hours of every working weekday. All working weekdays share the same hours. |
days |
Option<[bool; 7]> |
None = Monday-Friday |
Working weekdays. Index 0 is Sunday, index 6 is Saturday. true marks a working day. |
dates |
BTreeMap<chrono::NaiveDate, DayRule> |
empty | Date exceptions. An entry replaces the weekday rule for that date. |
hours#
pub hours:
Each TimeRange is one working interval within the day. The order of the ranges doesn't matter. An empty list means no working hours on any weekday, so only dates entries can add working time.
days#
pub days:
A weekday marked false has no working time unless a dates entry overrides it.
dates#
pub dates:
Per-date overrides, keyed by calendar date. The DayRule for a date wins over days and hours.
Validation#
A project with an invalid Worktime is rejected when it's loaded, with an InputError of kind Validation:
| Problem | Error path |
|---|---|
A range in hours is outside 00:00-24:00 |
calendars[{i}].worktime.hours |
Ranges in dates entries are checked as described on DayRule.
Example#
The example uses chrono for the date keys: cargo add chrono.
use BTreeMap;
use NaiveDate;
use ;
Related#
CalendarData- the calendar that holds this worktimeTimeRange- one interval of working hoursDayRule- the working time of one date exception- Working time and calendars - weekly hours, weekdays and holidays in practice