# Class CalendarExtensions OptimaJet.Workflow.Core.Runtime.Calendars.CalendarExtensions Provides extension methods for configuring [Calendar](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Runtime.Calendars/Calendar/) instances and calculating intervals using workflow calendar rules. Namespace: [OptimaJet.Workflow.Core.Runtime.Calendars](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Runtime.Calendars/) ```csharp 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](https://learn.microsoft.com/dotnet/api/system.timespan) value that can be added to `startDateTime` to get the target time. | ### Exceptions | Type | Description | | --- | --- | | `ArgumentNullException` | Thrown when `value` is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/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)](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Helpers/HelperDateTime/). `public static Calendar SetWorkingHours(this Calendar calendar, TimeSpan workingHours)` Sets the total working hours per workday and returns the same [Calendar](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Runtime.Calendars/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](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Runtime.Calendars/Calendar/). | ### Remarks The value is normalized using [HelperDateTime.Floor(TimeSpan)](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Helpers/HelperDateTime/), 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](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Runtime.Calendars/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](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Runtime.Calendars/Calendar/). | ### Remarks The value is normalized using [HelperDateTime.Floor(TimeSpan)](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Helpers/HelperDateTime/), so seconds and milliseconds are dropped. `public static Calendar SetWeekends(this Calendar calendar, params DayOfWeek[] weekends)` Adds the specified weekend days to [Calendar.Weekends](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Runtime.Calendars/Calendar/) and returns the same [Calendar](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Runtime.Calendars/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](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null). | `public static Calendar SetYears(this Calendar calendar, params Year[] years)` Adds year-level settings to the calendar and returns the same [Calendar](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Runtime.Calendars/Calendar/) instance. ### Parameters | Name | Type | Description | | --- | --- | --- | | `calendar` | `Calendar` | Calendar instance to update. | | `years` | `Year[]` | [Year](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Runtime.Calendars/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](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Runtime.Calendars/Year/) already exists in [Calendar.Years](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Runtime.Calendars/Calendar/). | [Previous Calendar](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Runtime.Calendars/Calendar/) [Next ICalendar](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Runtime.Calendars/ICalendar/)