adds a calendar into Gantt
| calendar | CalendarConfig | an object with configuration of the calendar |
| string | the id of the calendar |
// adding a previously created calendar
const calendarId = gantt.addCalendar(calendar);
// adding a calendar with a new config (the "days" property is set as array)
const calendarId = gantt.addCalendar({
id: "custom", // optional
worktime: {
hours: ["8:00-17:00"],
days: [1, 1, 1, 1, 1, 1, 1]
}
});
// adding a calendar with a new config (the "days" property is set as object)
const calendarId = gantt.addCalendar({
id: "global", // the calendar id is optional
worktime: {
hours: ["8:00-12:00", "13:00-17:00"], // global work hours for weekdays
days: {
weekdays: [0, 1, 1, 1, 1, 1, 0],
dates: {
"2025-04-06": true, // override work hours for a specific date
"2025-04-08": false,
"2025-04-09": ["9:00-15:00"]
}
},
customWeeks: {
lastMonthOfTheYear: {
from: new Date(2025, 11, 1),
to: new Date(2026, 0, 1),
hours: ["9:00-13:00"],
days: {
weekdays: [0, 1, 1, 1, 1, 0, 0],
dates: {
"2025-12-08": true,
"2025-12-09": false,
"2025-12-10": ["9:00-15:00"]
}
}
}
}
}
});
const calendar = gantt.getCalendar(calendarId);
The calendar configuration object can contain the following attributes:
Instead of the number of a week day, you can also set custom working hours for this day. For example:
const calendar = {
id: "calendar1", // optional
worktime: {
hours: ["8:00-17:00"],
days: [0, 1, 1, 1, ["12:00-17:00"], 1, 0] }
}
where ["12:00-17:00"] are working hours from 12 pm to 17 pm for Thursday.
There is a possibility to configure different working time rules for different periods of time by using the customWeeks attribute:
gantt.addCalendar({
id: "global", // optional
worktime: {
hours: ["8:00-17:00"],
days: [1, 1, 1, 1, 1, 1, 1],
customWeeks: {
winter: {
from: new Date(2025, 11, 1), // December 1st, 2025
to: new Date(2026, 2, 1), // March 1st, 00:00, 2026
hours: ["9:00-13:00", "14:00-16:00"],
days: [1, 1, 1, 1, 0, 0, 0]
}
}
}
});
You can also specify working hours for certain dates by setting them in the dates property of the days object (both for the worktime attribute and the customWeeks property). For example:
const calendar = {
id: "calendar1", // optional
worktime: {
hours: ["8:00-17:00"],
days: {
dates: {
"2025-04-09": ["9:00-15:00"]
}
},
customWeeks: {
winter: {
from: new Date(2025, 11, 1), // December 1st, 2025
to: new Date(2026, 2, 1), // March 1st, 00:00, 2026
hours: ["9:00-13:00", "14:00-16:00"],
days: {
dates: {
"2026-01-02": ["9:00-15:00"]
}
}
}
}
}
}