Premium support for our pure JavaScript UI components


Post by MauriceLapre »

Hi,

From my HR system backend, I'm fetching employees shifts and turning that into calenders with isWorking: true intervals. That's working fine. But they can make availability exceptions, like a meeting or holiday. That's registered not as non-working hours, but as "new" amount of available hours. So, I need to modify a specific interval to change the available hours (startDate/endDate).

E.g. an employee normally has 8 working hours on 27-05 from 8am to 4pm, fetched from his assigned shift. He has a meeting in the morning of 2 hours that day (the exception), so has new available hours as 6. I tried:

resCalendar.addInterval({
		startDate : exceptionsData[e].startDate, // being 27-05-2022 10:00
		endDate   : exceptionsData[e].endDate, // being 27-05-2022 16:00
		isWorking : true
	});

But that's not doing anything to the existing interval.

Of course, I could also add an isWorking: false interval, which works, but then I need to fetch the interval (working hours) of that specific day to calculate the "unavailability".

How can I achieve this, either change an existing working interval or get a specific one to be able to create a non-working interval?

Thank you.


Post by alex.l »

How can I achieve this, either change an existing working interval or get a specific one to be able to create a non-working interval?

You already described the correct way to do that - add isWorking: false interval for first 2 hours in that day, or remove existed interval for that day and add a new one.

Nothing happened in your case because you already have a record that gives 8 hours working interval for that day, so this one just duplicates working time.

calendarModel has intervals property, you could find interval you need by startDate or id, and remove it using calendar.removeInterval(interval) method, after that add a new one that you need.

All the best,
Alex


Post by MauriceLapre »

Hi Alex,

Thanks for your response. Couple of things. My resource calendars are based on recurring intervals:

rescal-intervals.png
rescal-intervals.png (30.62 KiB) Viewed 558 times

If I want to go with approach 1 (add an isWorking: false interval), I'd need the working hours for that specific day/datetime so I can calculate the new working hours. calendar.isWorkingTime only gives me a boolean, not the available hours. Is there an easy way to get this, other than working out on what day of the week the exception is, get the recurrent interval for that day, do date parsing and diffs on the recurring start- and end date to get the hours?

And if I want to go with approach 2 (removing the interval and adding a new one), how can I remove an interval for a specific date and not a recurring one (so the next week the default availability remains)?
By the way, calendar.removeInterval is not the API docs... but if it's available, it could surely help me with this :)


Post by alex.l »

There is a not documented method

// Returns working time ranges between the 2 dates. 
calendar.getWorkingTimeRanges (startDate : Date, endDate : Date)

We will add docs in the next patch release.

Intervals also has private field priority. It equals to 20 for recurring intervals and 30 for static intervals.
If you add another 2 intervals like

                    {
                        "startDate" : "2019-01-15",
                        "endDate"   : "2019-01-16",
                        "isWorking" : false
                    },
                    {
                        "startDate" : "2019-01-15T12:00:00",
                        "endDate"   : "2019-01-15T18:00:00",
                        "isWorking" : true,
                        "priority"  : 31
                    }

It will override the recurring rule for that day.

All the best,
Alex


Post by MauriceLapre »

Adding those 2 intervals seems to work, but they are applied to the complete calendar instead of to that particular resource only. Other resources having that same calendar then also have those intervals. That's not my intention, they are personal exceptions. How do I get that to work?


Post by alex.l »

If you need to have that on the resource only, try to create another calendar, based on main calendar, assign it to the resource you need and add intervals into child calendar.

All the best,
Alex


Post by MauriceLapre »

That's working nicely, thanks!


Post Reply