Business Calendar: Difference between revisions

From QPR ProcessAnalyzer Wiki
Jump to navigation Jump to search
No edit summary
Line 28: Line 28:
Durations can be calculated by using the '''timeDiff''' function in the business calendar as follows:
Durations can be calculated by using the '''timeDiff''' function in the business calendar as follows:
<pre>
<pre>
let calendar = BusinessCalendar({ ... });
let calendar = BusinessCalendar({...});
calendar.timeDiff(date1, date2);
calendar.timeDiff(date1, date2);
</pre>
</pre>

Revision as of 21:03, 1 December 2020

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 can be calculated by using the timeDiff function in the business calendar as follows:

let calendar = BusinessCalendar({...});
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" ]
  }
)
calendar.timeDiff(DateTime(2020, 12, 1), DateTime(2021, 1, 1));