Greeting,
How can I get total working hours of a given task?
My Objective to calculate cost of a task based on resources added to the task and the resource cost is in Hours
For example I have task which starts on 19-Sep-2022
and ending on 26-Sep-2022
and I have added a global Calendar, which has 5 days of working and Saturday and Sunday as off day.
So the list will look as below;
1. 19-Sep-2022 -- Working -- (8Hours)
2. 20-Sep-2022 -- Working -- (8Hours)
3. 21-Sep-2022 -- Working -- (8Hours)
4. 22-Sep-2022 -- Working -- (8Hours)
5. 23-Sep-2022 -- Working -- (8Hours)
6. 24-Sep-2022 -- Not Working -- (0Hours)
7. 25-Sep-2022 -- Not Working -- (0Hours)
8. 26-Sep-2022 -- Working -- (8Hours)
So if calculated the total hour taken by the task is 48 Hours
How can I get this using DHTMLX gantt?
I tried below, but its wrong as gantt.getWorkHours(<Date>)
giving me 08:00-12:00,13:00-17:00
calculateWorkHours: task => {
let startDate = task.start_date;
let endDate = task.end_date;
let totalWorkHours = 0;
while(startDate.getTime() <= endDate.getTime()){
if(gantt.isWorkTime(startDate)) {
totalWorkHours += gantt.getWorkHours(startDate);
}
startDate = gantt.date.add(startDate, 1, 'day');
}
return totalWorkHours;
}