Premium support for our pure JavaScript UI components


Post by kalai »

  1. How to get working hours/ days also between start and end date based on calendar.
  2. How to get working hour for particular date in range of start and end date with calendar.
  3. How to iterate all the dates between start and end date and get each date working hours on the basis of calendar.

Post by saki »

  1. 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))
  2. https://bryntum.com/docs/gantt/#Gantt/model/CalendarModel#function-skipNonWorkingTime Usage:
    project.calendar.skipNonWorkingTime(new Date(2019,0,26))
  3. 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

Post by saki »

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.

Post by kalai »

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

Post by saki »

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;

Post by kalai »

I am not able to find any ProjectModel library, So can you tell from which library i have to import ProjectModel


Post by mats »

Please see https://bryntum.com/docs/gantt/#Gantt/model/ProjectModel

Import it from the regular Gantt bundle.


Post by kalai »

I am using Bryntum in Node JS side with Bryntum Engine and there is no ProjectModel class and regular Gantt bundle as well, So how i can call calculateDurationMs() and skipNonWorkingTime() function with calendar.


Post by arcady »

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

	  }

Post by arcady »

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).


Post Reply