Business Calendar
The business calendar defines a weekly calendar for e.g. working/office/factory hours, which is used in the duration calculations to determine the duration where only the working hours have been taken into account (instead of 24h/days).
Business Calendar Object
In the expression language, a business calendar is created using the BusinessCalendar function which takes the calendar definition as the following structure:
BusinessCalendar(#{ "weeklyWorkingHours": [ #{ "weekDay": 1, "startHour": 8, "endHour": 16 }, #{ "weekDay": 2, "startHour": 8, "endHour": 11 }, #{ "weekDay": 2, "startHour": 12, "endHour": 17 }, #{ "weekDay": 3, "startHour": 8, "endHour": 16 }, #{ "weekDay": 4, "startHour": 8, "endHour": 16 }, #{ "weekDay": 5, "startHour": 8, "endHour": 15 } ], "exceptionDays": [ "2020-12-06", "2020-12-24", "2020-12-25", "2020-12-26", "2021-01-01", "2021-01-06" ] })
The previous example defines the following weekly schedule: Monday 8-16, Tuesday 8-11 and 12-17, Wednesday 8-16, Thursday 8-16 and Friday 8-15. Note that there is no working time in Saturday and Sunday, because they are not defined in the calendar.
The structure in the business calendar initialization has the following properties:
- weeklyWorkingHours: Defines the weekly working calendar. The items in the array are individual working periods within each day. There can be several working periods in the same weekday. The weekDay is defined as a number between 0 (Sunday) and 6 (Saturday). The startHour and endHour needs to be between 0 and 24. If no weekly schedule is defined, 24h/days calendar is assumed.
- exceptionDays: All the dates, when there is not working time, e.g. holidays. Exception days are defined as a string array where each day is defined using format yyyy-MM-dd. Defining exception days is not mandatory for in the business calendar.
Duration Calculation
Durations using the business calendar are calculated by using the timeDiff function of the business calendar as follows:
let calendar = BusinessCalendar(#{...}); let duration1 = calendar.timeDiff(date1, date2);
Example:
let calendar = BusinessCalendar(#{ "weeklyWorkingHours": [ #{ "weekDay": 1, "startHour": 8, "endHour": 16 }, #{ "weekDay": 2, "startHour": 8, "endHour": 11 }, #{ "weekDay": 2, "startHour": 12, "endHour": 17 } ], "exceptionDays": [ "2020-12-06", "2020-12-24", "2020-12-25", "2020-12-26", "2021-01-01", "2021-01-06" ] }) let duration1 = calendar.timeDiff(DateTime(2020, 12, 1), DateTime(2021, 1, 1));