Calandar with only specific working days

I’m trying to create a calendar that defines specific working dates – only these few dates should be considered as working days. I’ve tried creating a calendar using addCalendar with days: [0,0,0,0,0,0,0], then using setWorkTime on the calendar to specify the working dates, but this doesn’t work (I believe the addCalendar is failing if all the days are off, even though no error is generated).

Is what I’m trying to do even possible? Would it be applied correctly to a task?

Hello @Mat_Beard ,

Unfortunately, it’s not possible to apply worktime settings that don’t include any working days/hours. 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] for addCalendar will not work as expected. So at least one day should be specified as a working day.

Please check this article.

But it’s possible to make some months or even years have only non-working days using the customWeeks property. You only need to specify the necessary period and mark days within this period as non-working:

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

Please check the example of how it can be implemented: DHTMLX Snippet Tool.

Best regards,
Valeria Ivashkeivch
DHTMLX Support Engineer

Hi,

Thanks for the provided example. It’s not really working as expected though.

The working and non-working days are displayed in different colours, but they don’t have any effect on the tasks: if there are only 2 working days, then shouldn’t a task with a duration of 2 days be ‘forced’ to use these two days?

Basically I’m trying to create a task with a duration of 3 days, but those 3 days may be several days or weeks apart. The task should automatically span the defined working days.

Is this possible or am I wasting my time even trying?

Thanks again.

Hello @Mat_Beard,

The way Gantt works with working time is the following: when you enable work_time and configure calendars with working hours/days, the task duration is calculated only in working time. For example, if a task starts on April 1st and has a duration of 3 days, but April 2nd and 3rd are weekends (non-working), the task will automatically extend until April 5th, so that it still occupies exactly 3 working days.

As you can see from this code snippet, Task #1 has a duration of 2 days and starts on 11 April 2025. However, since work_time is enabled, the task’s duration is calculated in working hours and it spans to 2 June 2025 (because April 12 - 1 June are non-working days).

Best regards,
Valeria Ivashkeivch
DHTMLX Support Engineer

Thanks for the clarification and the example. I can see that’s working as expected.

Can you please explain the order of priority when using setWorkTime? For example, if I define a customWeeks property that sets an entire year as hours: false (i.e. non-working) and then use several calls to setWorkTime to specify a few dates as working, will these dates take priority?

If not, do I need to use multiple customWeeks and leave ‘gaps’ for the dates on which I want to work?

Also, does it make any difference if I’m altering the ‘global’ calendar, or a calendar added with addCalendar?

Thanks for your advice… much appreciated.

Hello,

If you define a non-working period using the customWeeks property and you want to make some dates working days, then you should create several periods in customWeeks leaving gaps for working days, and set working hours for the necessary dates.
https://docs.dhtmlx.com/gantt/api__gantt_setworktime.html#:~:text=order%20to%20specify-,working%20days,-/hours%20within%20the

Does it make any difference if I’m altering the ‘global’ calendar, or a calendar added with addCalendar?

The only difference between the global calendar and a calendar added with addCalendar is scope: the global calendar affects all tasks, while additional calendars can be assigned to individual tasks, projects, or resources.

  • A global calendar is a default calendar that applies to all tasks unless a custom calendar is specified. You modify it directly using gantt.setWorkTime().
  • Custom calendars are created using gantt.addCalendar() and can be assigned to specific tasks or resources. To modify a custom calendar, you first get its instance and then call setWorkTime on that instance.
    Work Time Calculation Gantt Docs

Best regards,
Valeria Ivashkeivch
DHTMLX Support Engineer

Thanks. That’s all clear now.

Is it possible to make a suggestion? Although it’s possible to create a calendar where only certain dates are classed as working, it’s incredibly clunky. Perhaps this could be addressed in a future version?

Hello @Mat_Beard,

The current behavior of the working calendar requires the calendar to have at least one day in the week specified as a working day to ensure that calculateEndDate will return a valid date for any given date. Therefore, the use of customWeeks is still unavoidable. But I passed your request to the dev team. Perhaps this behavior of the calendar will be revised. I will notify you on any updates on this case.

In the upcoming Gantt v9.1.0 update, we are planning to extend the configuration options for the addCalendar method. It will then be possible to set customWeeks and specify working hours for specific dates directly in the addCalendar configuration

Best regards,
Valeria Ivashkeivch
DHTMLX Support Engineer

That sounds perfect. Thanks for your help!

1 Like