1. CalculateWorkTime

    Article: AN0001602Updated:

    This object provides functions for calculation of work time.

    By means of function CalculateEndDate certain work time can be added. The function reflects work time in various days, holidays and changed work time in particular days.

     

    Name Description
    TimeSpan Elapsed Time from start of timer.
    void AddDay(DayOfWeek day, TimeSpan fromTime, TimeSpan toTime) Method adds work time for particular day in week into calendar.
    void AddDay(DayOfWeek day, DateTime fromTime, DateTime toTime) Method adds work time for particular day in week into calendar.
    void AddDay(DayOfWeek day, int fromMinute, int toMinute) Method adds work time for particular day in week into calendar.
    void AddSpecialDay(DateTime date, TimeSpan fromTime, TimeSpan toTime) Method adds work time for particular day into calendar.
    void AddSpecialDay(DateTime date, DateTime fromTime, DateTime toTime) Method adds work time for particular day into calendar.
    void AddSpecialDay(DateTime date, int fromMinute, int toMinute) Method adds work time for particular day into calendar.
    void AddSpecialDay(DateTime date, FromToIntervalList ft) Method adds work time for particular day into calendar.
    void AddWeek(int fromMinute, int toMinute) Method adds work time for days Monday to Friday into calendar.
    void AddWeekEnd(int fromMinute, int toMinute) Method adds work time for Saturday and Sunday into calendar.
    DateTime CalculateEndDate(DateTime dateFrom, int addMinutes) Function returns a final date with regard work time defined in calendar.
    string CalendarCode Calendar code
    void ClearCache() Method clears settings of days, special days and configuration.
    void ClearDay(DayOfWeek day) Method clears settings of days.
    void ClearAllDay() Method clears settings of special days.
    WorkTimeConfiguration Configuration Calendar configuration.
    int DaysCount Number of definitions for days in week.
    string GetCalendarUrl() Function returns URL address for calendar display.
    void Initialize() Performs calendar initialization.
    void Initialize(WorkTimeConfiguration configuration) Performs calendar initialization with the defined configuration.
    int SpecialDaysCount Number of definitions for special days.

    DAY indicates  in the functions days in week (Monday - Sunday) which form a regular time. It is possible to define more intervals for each day, when the work time is applied. Intervals can overlap (they are merged internally). In this way it is possible to set the work time e.g. 8:30-12:00 and 13:00-17:30.

    SPECIALDAY  is used in functions for particular days (e.g. 24.12., 31.12. ...) which represents an exception. For such day you can define another work time (none, reduced, extended...). When calculating end time by the function CalculateEndDate are these days priority against DAY, i.e. if for a particular day special day is defined, then it is used. Otherwise DAY definition is used.

    Initialization

    Before calculation it is necessary to perform calendar object initialization. This can be done in two ways:

    • fill in the regular and special days directly into the calendar object
    • set the configuration for reading data from classes set for calendar

    In the first case you need to set everything by means of scripts. In the second example you can easily click all the work time and exceptions simply by means of user interface.

    Calculation of the end time

    Function CalculateEndDate is used for the end time calculation. You set the initial time (i.g. occurence of an incident) in the parameter dateFrom and work time, that shall be added in the parameter addMinutes. The functon calculates the final time and returns it. There are serveral rules applied for the calculation:

    • If there is no definition for the calculated day neither in DAY nor in SPECIALDAY, the day considered without working tme and is skipped.
    • The least used unit for input is a minute.
    • If the initial date is out of working hour, than it is move at the beginning of the closest work time in future, i.e. if e.g. incident occurs on Sunday, that is not set as an working day and the time for calculation is 2 hours, than the end day will be on Monday 2 hours after the work time start, supposing Monday is set as a working day.

    Example

    //read standard SLA calendar

    var cwt = OG.Utils.GetSLACalculateWorkTime();

    var d = cwt.CalculateEndDate(OG.DateTime.Now, 480);     //adding 8 hours

    //conversion of a date to text

    var s = d.ToString('dd.MM.yyyy HH:mm:ss');

×