Hello @Daniele,
Thank you for the provided details.
Based on your description, it looks like you are trying to do two things at once, and they require different approaches in Gantt:
- Partial leave within a working day (e.g., 9:00–10:00 on a working day)
If you want to override working hours for the specific date on the calendar, you can change it using the setWorkTime method:
const calendar = gantt.getCalendar("calendarId");
calendar.setWorkTime({
date: new Date(2025, 5, 9),
hours: ["8:00-9:00", "10:00-12:00", "14:00-17:00"]
});
calendar.isWorkTime({ date: new Date(2025, 5, 9, 9, 0), unit: "hour" }); // false
calendar.isWorkTime({ date: new Date(2025, 5, 9, 8, 0), unit: "hour" }); // true
isWorkTime with unit: "hour" does take time into account - it checks whether the time falls into the working intervals returned by getWorkHours(). In your current setup, 9:00 is still treated as working time because the base schedule (8:00–12:00) is still in effect.
unsetWorkTime removes existing day-level rules; it does not create hour-level exceptions.
A configuration like hours: [] with days: [0,0,0,0,0,0,0] inside customWeeks is also not the right approach here. Gantt requires the calendar to retain at least some working time at the base level. If you try to do so, then the method for one of the working days will be ignored, and it will still contain working hours. That’s why setting this configuration days: [0,0,0,0,0,0,0] will not work as expected. Please check this article.
- A date range with a different working schedule (or fully non-working days)
If your goal is to change the working hours for a period of days, you can use customWeeks:
gantt.addCalendar({
id: "resource1",
worktime: {
hours: ["8:00-12:00", "14:00-17:00"],
days: [0, 1, 1, 1, 1, 1, 0],
customWeeks: {
leavePeriod: {
from: new Date(2025, 5, 1),
to: new Date(2025, 5, 15),
hours: ["8:00-9:00", "10:00-12:00", "14:00-17:00"],
days: [0, 1, 1, 1, 1, 1, 0]
}
}
}
});
Fully non-working periods - use hours: false, and then set working hours only for the dates that should remain working:
gantt.setWorkTime({ date: new Date(2025, 3, 10), hours: ["8:00-12:00"] });
gantt.setWorkTime({ date: new Date(2025, 3, 11), hours: ["13:00-17:00"] });
gantt.setWorkTime({
customWeeks: {
period1: {
from: new Date(2025, 3, 1),
to: new Date(2025, 3, 10),
hours: false
},
period2: {
from: new Date(2025, 3, 12),
to: new Date(2025, 5, 1),
hours: false
}
}
});
See: Different working hours for different time spans.
- Override working time for specific dates (Gantt 9.1.0+)
Starting from v9.1.0, you can define date-specific overrides directly in the calendar configuration using the days.dates object. After upgrading to 9.1.0+, the config could look like:
gantt.addCalendar({
id: "resource1",
worktime: {
hours: ["8:00-12:00", "14:00-17:00"],
days: {
weekdays: [0, 1, 1, 1, 1, 1, 0],
dates: {
"2025-06-09": ["8:00-9:00", "10:00-12:00", "14:00-17:00"],
"2025-06-10": false
}
}
}
});
Best regards,
Valeria Ivashkevich
DHTMLX Support Engineer