Assembly: OptimaJet.Workflow.Core

Class CalendarExtensions

OptimaJet.Workflow.Core.Runtime.Calendars.CalendarExtensions

Provides extension methods for configuring Calendar instances and calculating intervals using workflow calendar rules.

public static class CalendarExtensions

Methods

public static TimeSpan GetInterval(this ICalendar calendar, string value, DateTime startDateTime) #
Gets the interval represented by value, optionally applying calendar-specific working-day rules.

Parameters

Name
Type
Description
calendar
ICalendar
Calendar settings used for working-time values.
value
String
A timer expression string.
startDateTime
DateTime
The start point for the interval calculation.

Returns

Type
Description
TimeSpan
A TimeSpan value that can be added to startDateTime to get the target time.

Exceptions

Type
Description
ArgumentNullException
Thrown when value is null.
ArgumentException
Thrown when value mixes calendar and non-calendar interval units.

Remarks

If value contains calendar-prefixed units (wyear, wmonth, wdays, whours, wminutes), calendar working-day logic is used. Otherwise normal interval parsing is delegated to HelperDateTime.GetInterval(string).
public static Calendar SetWorkingHours(this Calendar calendar, TimeSpan workingHours) #
Sets the total working hours per workday and returns the same Calendar instance.

Parameters

Name
Type
Description
calendar
Calendar
Calendar instance to update.
workingHours
TimeSpan
Working hours to configure.

Returns

Type
Description
Calendar
The updated calendar.

Exceptions

Type
Description
ArgumentOutOfRangeException
Thrown if workingHours is greater than 24 hours, or if it causes the workday to exceed 24 hours when combined with Calendar.StartOfWork.

Remarks

The value is normalized using HelperDateTime.Floor(TimeSpan), so seconds and milliseconds are dropped.
public static Calendar SetStartOfWork(this Calendar calendar, TimeSpan startTimeOfDay) #
Sets the start time of the workday and returns the same Calendar instance.

Parameters

Name
Type
Description
calendar
Calendar
Calendar instance to update.
startTimeOfDay
TimeSpan
Time of day when the working period starts.

Returns

Type
Description
Calendar
The updated calendar.

Exceptions

Type
Description
ArgumentOutOfRangeException
Thrown if startTimeOfDay is greater than 24 hours, or if it causes the workday to exceed 24 hours with Calendar.WorkingHours.

Remarks

The value is normalized using HelperDateTime.Floor(TimeSpan), so seconds and milliseconds are dropped.
public static Calendar SetWeekends(this Calendar calendar, params DayOfWeek[] weekends) #
Adds the specified weekend days to Calendar.Weekends and returns the same Calendar instance.

Parameters

Name
Type
Description
calendar
Calendar
Calendar instance to update.
weekends
DayOfWeek[]
Weekday values to add as weekends.

Returns

Type
Description
Calendar
The updated calendar.

Exceptions

Type
Description
ArgumentNullException
Thrown when weekends is null.
public static Calendar SetYears(this Calendar calendar, params Year[] years) #
Adds year-level settings to the calendar and returns the same Calendar instance.

Parameters

Name
Type
Description
calendar
Calendar
Calendar instance to update.
years
Year[]
Year objects to register by year number.

Returns

Type
Description
Calendar
The updated calendar.

Exceptions

Type
Description
ArgumentException
Thrown if a value with the same Year.YearNumber already exists in Calendar.Years.