[Canonical page](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/day-rule/>)
[Full documentation index](<https://docs.dhtmlx.com/planning-engine/llms.txt>)


# DayRule

Working time of one calendar date. A `DayRule` is the value type of [`Worktime::dates`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/worktime.md#dates>), keyed by `chrono::NaiveDate`. On that date the rule replaces the weekday rule from `Worktime::days`, in both directions: it can turn a working weekday off or a weekend day on.

## Declaration

```rust
#[derive(Clone, Debug)]
pub enum DayRule {
    Off,
    On,
    Hours(Vec<TimeRange>),
}
```

## Variants

| Variant | Description |
|---|---|
| `Off` | Non-working date, such as a holiday. |
| `On` | Working date with the calendar's regular hours ([`Worktime::hours`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/worktime.md#hours>)). |
| `Hours(Vec<TimeRange>)` | Working date with these hours instead of the regular ones. An empty list works like `Off`. |

The ranges in `Hours` follow the [`TimeRange`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/time-range.md>) rules. An invalid range is rejected with [`Error::Input`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/errors/error.md>) at the path `calendars[i].worktime.dates[YYYY-MM-DD]`.

## Example

A calendar with a holiday, a working Saturday and a short day:

```rust
use std::collections::BTreeMap;

use chrono::NaiveDate;
use plen_core::{CalendarData, DayRule, TimeRange, Worktime};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let date = |y, m, d| NaiveDate::from_ymd_opt(y, m, d).ok_or("invalid date");

    let mut dates = BTreeMap::new();
    dates.insert(date(2026, 12, 25)?, DayRule::Off);
    dates.insert(date(2026, 12, 19)?, DayRule::On);
    dates.insert(
        date(2026, 12, 24)?,
        DayRule::Hours(vec![TimeRange { start: 8 * 60, end: 12 * 60 }]),
    );

    let calendar = CalendarData {
        id: "global".into(),
        worktime: Some(Worktime { dates, ..Worktime::default() }),
    };
    println!("{calendar:?}");
    Ok(())
}
```

The example uses `chrono` for the date keys, so add it next to the library: `cargo add chrono`.

## Related

- [`Worktime`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/worktime.md>) - holds the date exceptions keyed by date
- [`TimeRange`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/time-range.md>) - the working intervals of an `Hours` rule
- [`CalendarData`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/calendar-data.md>) - the calendar the exception belongs to
- [Working time and calendars](<https://docs.dhtmlx.com/planning-engine/rust/scheduling/working-time-calendars.md>) - holidays and working days off the regular week
