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


# CalendarData

A named working-time calendar. Calendars go in [`ProjectData::calendars`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/project-data.md>); tasks and resources point at them by id through their `calendar_id` fields. Build it with a struct literal.

## Declaration

```rust
pub struct CalendarData {
    pub id: Id,
    pub worktime: Option<Worktime>,
}
```

## Fields

| Field | Type | Default | Description |
|---|---|---|---|
| `id` | [`Id`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/id.md>) | required | Calendar id, unique among the project's calendars. `"global"` replaces the built-in default calendar (Monday to Friday, 08:00-12:00 and 13:00-17:00). |
| `worktime` | `Option<`[`Worktime`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/worktime.md>)`>` | `None` | Working hours, weekdays and date exceptions. `None` gives the built-in hours and weekdays with no exceptions. |

### id

```rust
pub id: Id
```

The key that [`TaskData::calendar_id`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/task-data.md#calendar_id>) and [`ResourceData::calendar_id`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/resource-data.md#calendar_id>) refer to. Without a calendar named `"global"`, the project still has one: the built-in Monday to Friday, 08:00-12:00 and 13:00-17:00.

### worktime

```rust
pub worktime: Option<Worktime>
```

When the calendar works. `None` is the same as `Some(Worktime::default())`.

## Errors

A calendar fails validation with [`Error::Input`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/errors/error.md>) at the path `calendars[i]` when:

- its `id` repeats the id of an earlier calendar in the list
- its `worktime` leaves no working time at all

Errors inside `worktime` are reported at `calendars[i].worktime...`; see [`Worktime`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/worktime.md>) and [`TimeRange`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/time-range.md>).

To change a calendar, see [`SchedulingChanges`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/changes/scheduling-changes.md>).

## Example

A project-wide calendar that works Monday to Friday, 09:00-17:00, with one holiday, and a second calendar that keeps the default hours but works Saturdays:

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

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

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let holiday = NaiveDate::from_ymd_opt(2026, 8, 14).ok_or("invalid date")?;

    let global = CalendarData {
        id: "global".into(),
        worktime: Some(Worktime {
            hours: Some(vec![TimeRange { start: 9 * 60, end: 17 * 60 }]),
            days: Some([false, true, true, true, true, true, false]), // Sun..Sat
            dates: BTreeMap::from([(holiday, DayRule::Off)]),
        }),
    };

    let six_day = CalendarData {
        id: "six-day".into(),
        worktime: Some(Worktime {
            days: Some([false, true, true, true, true, true, true]),
            ..Default::default()
        }),
    };

    let data = ProjectData {
        calendars: vec![global, six_day],
        ..Default::default()
    };
    println!("{} calendars", data.calendars.len());
    Ok(())
}
```

`NaiveDate` comes from `chrono` (`cargo add chrono`).

For choosing which calendar a task or assignment works on, see [Working time and calendars](<https://docs.dhtmlx.com/planning-engine/rust/scheduling/working-time-calendars.md>).

## Related

- [`CalendarMode`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/calendar-mode.md>) - decides whether task or resource calendars place the work
- [`DayRule`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/day-rule.md>) - a date exception inside a calendar's worktime
- [`TaskData`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/task-data.md>) - tasks select a calendar through `calendar_id`
- [Working time and calendars](<https://docs.dhtmlx.com/planning-engine/rust/scheduling/working-time-calendars.md>) - defining calendars and assigning them to tasks and resources
