Premium support for our pure JavaScript UI components


Post by rahulranjan »

Hi We want difference between two days based on calendar for task . In hours unit


Post by alex.l »

Hi rahulranjan,

const duration = gantt.project.calendar.calculateDurationMs(startDate, endDate);
const durationInHours = gantt.project.convertDuration(duration, "millisecond", "hour");

https://bryntum.com/docs/gantt/engine/classes/_lib_engine_quark_model_abstractcalendarmixin_.abstractcalendarmixin.html#calculatedurationms
https://bryntum.com/docs/gantt/engine/classes/_lib_engine_quark_model_gantt_ganttprojectmixin_.ganttprojectmixin.html#convertduration

All the best,
Alex


Post by rahulranjan »

HI
For Each task there can be different calendars assigned to it
Let Say
Task 1 Cal 1
Task 2 Cal 2

Now when i selected task1 and i want difference between two dates based on Cal1 ?
Same carries for Task2 and Dates Difference will be based on Cal2

Because Each Calendar will have different working time duration


Post by alex.l »

Could you please describe your use case in more details?
Every calendar has this method. Just get the calendar that you need and calculate a duration.
gantt.project.calendar is a tree record, check its children.
If you want to get a calendar assigned to a task, use:
https://bryntum.com/docs/gantt/#Gantt/model/TaskModel#field-calendar

All the best,
Alex


Post by rahulranjan »

Hi Alex
We have Two native Fields of Date Type let us Date_1 and Date_2 for Each task we want to get the difference between this dates in hours but the difference should be calculated based on calendar assigned to each of task . Hope it makes you clear


Post by alex.l »

Ok, thanks! Then I hope you have all information now to continue?

All the best,
Alex


Post by rahulranjan »

No !!
Unable to get how to do it .


Post by rahulranjan »

alex.l wrote: Tue Feb 16, 2021 12:32 pm

Could you please describe your use case in more details?
Every calendar has this method. Just get the calendar that you need and calculate a duration.
gantt.project.calendar is a tree record, check its children.
If you want to get a calendar assigned to a task, use:
https://bryntum.com/docs/gantt/#Gantt/model/TaskModel#field-calendar

How to get the calendar of task and Pass it to gantt.project.calendar this ? for Date Difference calculation based on calendar


Post by rahulranjan »

How to pass which calendar is for selected task in the method you mentioned


Post by saki »

The above function calculateDurationMs takes 2 arguments that can be any dates (Date_1, Date_2). This is the method of calendar so you if you want to base the results on Cal_2 then you would call (pseudocode):

const cal2 = task2.calendar;
const duration = cal2.calculateDurationMs(task1.date1, task1.date2);

Post Reply