- How to get working hours/ days also between start and end date based on calendar.
- How to get working hour for particular date in range of start and end date with calendar.
- How to iterate all the dates between start and end date and get each date working hours on the basis of calendar.
Support Forum
- https://bryntum.com/docs/gantt/#Gantt/model/CalendarModel#function-calculateDurationMs This is a method on calendar. You can use it this way:
project.calendar.calculateDurationMs(new Date(2019,0,25), new Date(2019,0,27))
- https://bryntum.com/docs/gantt/#Gantt/model/CalendarModel#function-skipNonWorkingTime Usage:
project.calendar.skipNonWorkingTime(new Date(2019,0,26))
- You can iterate dates by any javascript loop method you want and you can use
calculateDurationMs
from midnight that day to midnight next day. For example:project.calendar.calculateDurationMs(new Date(2019,0,26), new Date(2019,0,27)) // returns 0 because Jan 26, 2019 was Saturday
A couple of more notes:
- You can use project.convertDuration to convert milliseconds to hours, such as:
project.convertDuration(86400000, 'millisecond', 'hour') // returns 24
- The above methods are called on a specific calendar so they will give correct answers based on that calendar only. However, speaking of task, its duration is calculated by intersection of multiple calendar (task, resource, project). See Task Scheduling Guide for details.
Thanks Saki for your valuable reply, But still i am facing some issue :
According to my use case, I need to call the function where i will be able to pass the start date and end date and in return which will provide me the "total number of working days" ,"total number of working hours during that range" and "working time for each day", all these three output must be according to the calendar.
For this i wrote the code, as per your reply when i am calling the calculateDurationMs and skipNonWorkingTime function, so it is throwing an error (node:10666) UnhandledPromiseRejectionWarning: TypeError: withCalendar.calculateDurationMs is not a function.
I am attaching the code i wrote, please look into that and give me the solution for that and If possible then please provide me some hints or practice code where i can do the required changes that fit to my use cases.
Thanks
Kalai
- Attachments
-
- gantt.js
- (14.37 KiB) Downloaded 69 times
I have spotted the following in your code:
line 10
:
const project = new GanttProjectMixin({
The mixin is not meant to be instantiated standalone but it is automatically mixed into ProjectModel. So the line should read:
const project = new ProjectModel({
line 579
:
let withCalendar = project.taskStore[i].calendar;
Use https://bryntum.com/docs/gantt/#Gantt/model/TaskModel#field-effectiveCalendar instead:
let withCalendar = project.taskStore[i].effectiveCalendar;
Please see https://bryntum.com/docs/gantt/#Gantt/model/ProjectModel
Import it from the regular Gantt bundle.
You need to wait for project.commitAsync()
completion to make sure the project has calculated all its identifiers:
await project.commitAsync();
for (let i = 0; i < project.taskStore.length; i++) {
let withCalendar = project.taskStore[i].calendar;
const getAssignmentById = withCalendar.calculateDurationMs(project.taskStore[i].startDate, project.taskStore[i].endDate);
}
Also instead of calendar I would recommend using effectiveCalendar (calendar
won't work if a task has no calendar assigned while effectiveCalendar
will fall back to the project calendar).