Task bar has more duration than actual duration in Database

Hey there, I am using the DHTMLX gantt PRO. Right now, I am working with ‘hours’ as setting it in duration_unit = ‘hour’

I’ve my own backend scheduler and engine in Java Spring. The issue I am facing is related to the length of taskBar on gantt. I am sending the calculated end_date for tasks respecting my own working hour and times

Days : Mon-Fri
Hours : 8-12, 1-5 PM

For eg, If I add a Task A starting on 16 PM with 3 hours, my backend engine will return end_date of next day 10 AM which is correct as per my own calendar rules

Now, the gantt shows the taskBar’s length to 18 hours ( I get to know this when I drag it to increase or decrease duration, it starts from 18 and not my actual 3 hour) which is a directly difference of start_date and end_date. 16 PM → to 10 AM next day = 18 hours, this works in a 24 hour cycle

This makes problem while dragging the task for duration change. If I want to add just one hour by dragging it, this will start from 18 and make it 19 and not actual 4. Due to this, this unwanted duration will be again sent to my backend scheduler and it will new calculated end_date which will make it even huge to show the task_bar on gantt and this will keep continue

How can I fix this to show task bar as per my duration value ? or if I can use any native property to stop gantt calculate this just based on start_date and end_date and show my own duration received from backend ?

I’m attaching the screenshot. Please not, duration_unit is in hours right now :

Hello @Rizwan ,

Thanks for reaching out!

The problem occurs because Gantt calculates duration in calendar time by default, including weekends and holidays. When work_time is not configured, Gantt includes non-working periods (like nights and weekends) in duration calculations, treating all days as 24-hour cycles. This explains why your 3-hour task spanning from 4 PM to 10 AM the next day displays as 18 hours (calendar time difference) instead of 3 working hours.

To fix this, you need to enable work time calculation and configure Gantt to respect your working hours (Mon-Fri, 8 AM-12 PM, 1 PM-5 PM).

Set gantt.config.work_time = true to exclude non-working periods from duration calculations and set the necessary working hours using the setWorkTime() method:

gantt.config.work_time = true;
gantt.config.duration_unit = "hour";
gantt.setWorkTime({ hours: ["8:00-12:00", "13:00-17:00"] });

Please check the example of how it can be implemented: Calculate working hours.

Best regards,
Valeria Ivashkevich
DHTMLX Support Engineer

1 Like

Thanks Valeria! setting setWorkTime worked and fixed the issue.

1 Like