Premium support for our pure JavaScript UI components


Post by rahulranjan »

How to get calendar hoursPerday based on Calendar id


Post by pmiklashevich »

Working hours per day is a variable value and depends on the day. You can use calculateDurationMs function and pass the interval you're interested in (start/end dates) to get the working time in milliseconds. Then you can convert the value into units you need using DateHelper.as function.

You can try it out in Advanced demo:

import DateHelper from '../../lib/Core/helper/DateHelper.js';
.....
const gantt = new Gantt({
    ....
});
.....
const
// calendar id to check working hours for
calendarId = 'general',
    // interval to check working hours for
    startDate = new Date(2019, 0, 14),
    endDate = new Date(2019, 0, 15);

const
    calendar = gantt.project.getCalendar(calendarId),
    workingMs = calendar.calculateDurationMs(startDate, endDate),
    workingHours = DateHelper.as('hour', workingMs, 'ms');

console.log(workingHours);

Pavlo Miklashevych
Sr. Frontend Developer


Post by rahulranjan »

HI
Thanks
Now if we have only duration in Hours and Start Date how we get duration in Days ?


Post by alex.l »

Please review our docs for https://www.bryntum.com/docs/gantt/#Core/helper/DateHelper and https://www.bryntum.com/docs/gantt/engine/classes/_lib_engine_quark_model_abstractcalendarmixin_.abstractcalendarmixin.html that Pavel provided.
You can convert duration to any units as well as calculate endDate/duration as you need.
https://www.bryntum.com/docs/gantt/engine/classes/_lib_engine_quark_model_abstractcalendarmixin_.abstractcalendarmixin.html#calculateenddate
https://www.bryntum.com/docs/gantt/#Core/helper/DateHelper#function-asMilliseconds-static

Regarding to your question:

Now if we have only duration in Hours and Start Date how we get duration in Days ?

If you already have duration, just convert in into units you need using https://www.bryntum.com/docs/gantt/#Core/helper/DateHelper#function-as-static:

DateHelper.as('day', durationInHours, 'hour');

All the best,
Alex

All the best,
Alex


Post Reply