CalendarData#

A named working calendar. Add instances to ProjectData.calendars and reference them by ID from TaskData.calendarId and ResourceData.calendarId. Create one with new CalendarData() and the fluent setters.

Declaration#

public class CalendarData extends ValueRecord implements DeepCloneable<CalendarData>

Constructors#

CalendarData()#

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 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 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.

Methods#

withId#

public CalendarData withId(Id value)

Assigns id and returns this instance for chaining.

Returns - this CalendarData.

withWorktime#

public CalendarData withWorktime(Worktime value)

Assigns worktime and returns this instance for chaining.

Returns - this CalendarData.

deepClone#

public CalendarData deepClone()

Returns a copy that shares no Worktime, list or map with this instance. Id is immutable and is shared.

Returns - a new CalendarData with the same values.

copy#

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#

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

Inherited from ValueRecord. Two CalendarData are equal when their id and worktime are equal. toString() lists both fields, for logging.

Errors#

In Validation.STRICT mode, the call that receives the data throws InputException with kind InputErrorKind.VALIDATION:

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 is false. The rules for hours, days and dates are listed on Worktime.

Example#

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);
  }
}