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


# CalendarData

A named working calendar. Add instances to [`ProjectData.calendars`](<https://docs.dhtmlx.com/planning-engine/java/api/data/project-data.md>) and reference them by ID from [`TaskData.calendarId`](<https://docs.dhtmlx.com/planning-engine/java/api/data/task-data.md>) and [`ResourceData.calendarId`](<https://docs.dhtmlx.com/planning-engine/java/api/data/resource-data.md>). Create one with `new CalendarData()` and the fluent setters.

## Declaration

```java
public class CalendarData extends ValueRecord implements DeepCloneable<CalendarData>
```

## Constructors

### CalendarData()

```java
public CalendarData()
```

Creates a calendar with every field at its default. Set `id` before the data reaches the engine.

## Fields

| Field | Type | Default | Description |
|---|---|---|---|
| `id` | [`Id`](<https://docs.dhtmlx.com/planning-engine/java/api/data/id.md>) | `null` | Calendar ID. Required: a `null` ID throws `NullPointerException` when the data is imported. `Id.str("global")` replaces the built-in default calendar. |
| `worktime` | [`Worktime`](<https://docs.dhtmlx.com/planning-engine/java/api/data/worktime.md>) | `null` | Working hours, weekdays and date exceptions. `null` gives the built-in working time: Monday to Friday, 08:00-12:00 and 13:00-17:00. |

### The `"global"` calendar

Every project has a calendar with the ID `"global"`. Without a `CalendarData` of that ID, it's Monday to Friday, 08:00-12:00 and 13:00-17:00. A `CalendarData` with `id = Id.str("global")` replaces it. Which tasks and assignments fall back to `"global"` is covered in [Working time and calendars](<https://docs.dhtmlx.com/planning-engine/java/scheduling/working-time-calendars.md>).

## Methods

### withId

```java
public CalendarData withId(Id value)
```

Assigns `id` and returns this instance for chaining.

**Returns** - this `CalendarData`.

### withWorktime

```java
public CalendarData withWorktime(Worktime value)
```

Assigns `worktime` and returns this instance for chaining.

**Returns** - this `CalendarData`.

### deepClone

```java
public CalendarData deepClone()
```

Returns a copy that shares no [`Worktime`](<https://docs.dhtmlx.com/planning-engine/java/api/data/worktime.md>), list or map with this instance. `Id` is immutable and is shared.

**Returns** - a new `CalendarData` with the same values.

### copy

```java
public CalendarData copy()
```

Returns a shallow copy. The copy shares the `worktime` object with this instance.

**Returns** - a new `CalendarData` with the same field values.

### equals, hashCode, toString

```java
public boolean equals(Object other)
public int hashCode()
public String toString()
```

Inherited from [`ValueRecord`](<https://docs.dhtmlx.com/planning-engine/java/api/support/value-record.md>). Two `CalendarData` are equal when their `id` and `worktime` are equal. `toString()` lists both fields, for logging.

## Errors

In [`Validation.STRICT`](<https://docs.dhtmlx.com/planning-engine/java/api/project/validation.md>) mode, the call that receives the data throws [`InputException`](<https://docs.dhtmlx.com/planning-engine/java/api/errors/input-exception.md>) with kind [`InputErrorKind.VALIDATION`](<https://docs.dhtmlx.com/planning-engine/java/api/errors/input-exception.md#inputerrorkind>):

| Path | When |
|---|---|
| `calendars[i]` | Two calendars share an ID (`"duplicate calendar id"`). IDs compare by their key, so `Id.num(1)` and `Id.str("1")` collide. In `Validation.REPAIR` mode the later calendar replaces the earlier one at the earlier position instead, and a note records it. |
| `calendars[i]` | The calendar has no working time at all: no working hours on any weekday and no date exception with hours (`"calendar has no working time"`). |

These checks also run when [`SchedulingConfig.useCalendars`](<https://docs.dhtmlx.com/planning-engine/java/api/data/scheduling-config.md>) is `false`. The rules for hours, days and dates are listed on [`Worktime`](<https://docs.dhtmlx.com/planning-engine/java/api/data/worktime.md>).

## Example

```java
import java.util.List;
import org.dhtmlx.plen.*;

public class CalendarDataExample {
  public static void main(String[] args) throws Exception {
    CalendarData partTime = new CalendarData()
        .withId(Id.str("part-time"))
        .withWorktime(new Worktime()
            // Monday, Wednesday and Friday; index 0 is Sunday.
            .withDays(new boolean[] {false, true, false, true, false, true, false})
            .withHours(List.of(new TimeRange(9 * 60, 13 * 60))));

    ProjectData data = new ProjectData()
        .withCalendars(List.of(partTime))
        .withTasks(List.of(
            new TaskData(Id.num(1))
                .withStartDate(Moment.fromYmdHm(2026, 3, 2, 9, 0))
                .withDuration(3.0)
                .withCalendarId(Id.str("part-time"))));

    ScheduleResult result = new Project().solve(data, new SolveOptions());
    System.out.println(result.updates);
  }
}
```

## Related

- [`Worktime`](<https://docs.dhtmlx.com/planning-engine/java/api/data/worktime.md>) - the working time it holds
- [`ProjectData`](<https://docs.dhtmlx.com/planning-engine/java/api/data/project-data.md>) - where calendars are listed
- [`CalendarMode`](<https://docs.dhtmlx.com/planning-engine/java/api/data/calendar-mode.md>) - which calendars place a task's work
- [Working time and calendars](<https://docs.dhtmlx.com/planning-engine/java/scheduling/working-time-calendars.md#defining-calendars>) - defining calendars and assigning them
