Get total working hours of a specific task

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

Hello,
If you want to calculate working hours depending on a custom calendar, you can use calculateDuration method to calculate the duration of a task:
https://docs.dhtmlx.com/gantt/api__gantt_calculateduration.html ;
Please check the example:
https://snippet.dhtmlx.com/15o6f29x ;
The simplest way is to create a variable with the amount of working hours and multiply this variable by the duration of the task.
Please check the example:
https://snippet.dhtmlx.com/aiq624a0 ;