Skip to content

Calendar

Represents a calendar object with business rules, providing asynchronous operations.

Remarks

The Calendar object is used to perform date and time arithmetic, such as adding or subtracting days, months, years, or hours. It also provides methods for changing time zones and obtaining the current date and time.

Calendar rules can be changed by using the StandardCalendar or WeekendCalendar objects. The StandardCalendar object represents a 7/24 calendar, while the WeekendCalendar object represents a 5/24 calendar.

If you need a calendar with specific rules, you may create new calendar with Calendar.Parse method.

Capabilities

Presets

Calendar Queries

  • Calendar.Today: Returns the current date and time in UTC time.
  • Calendar.GetDateTime: Returns the next valid date and time, according to calendar rules, after adding the given duration to the specified date.
  • Calendar.GetHoursInDay: Returns the total number of hours in the specified date.
  • Calendar.GetToday: Returns the current date and time in the specified time zone.

Date Arithmetic

  • Calendar.Add: Adds a specified number of hours to a DateTimeOffset value and returns the result.
  • Calendar.AddDays: Adds a specified number of days to a DateTimeOffset value and returns the next valid date and time according to the calendar rules.
  • Calendar.AddMonths: Adds a specified number of months to a DateTimeOffset value and returns the result.
  • Calendar.AddTimeSpan: Returns a new DateTimeOffset by adding a specified duration, considering calendar rules.
  • Calendar.AddYears: Adds a specified number of years to a DateTimeOffset value and returns the result.
  • Calendar.Subtract: Subtracts one date-time value from another and returns the difference in hours.

Async Date Arithmetic

Time Zones

Async Time Zones

Async Calendar Queries

Creation and Presets