Skip to content

$Calendar

Provides the default calendar instance with domain-specific calendar rules.

1
const $Calendar: Calendar;

Remarks

$Calendar is used to obtain the current date and time, perform date and time arithmetic (addition and subtraction), and manage time zone conversions.

$Calendar can be utilized in both client-side and server-side scripts. In server-side scripts, both synchronous and asynchronous methods are supported. However, client-side scripts are restricted to asynchronous methods due to their inherent asynchronous nature.

$Calendar defaults to using the domain calendar rules. For specific calendar implementations, refer to the Calendar.StandardCalendar or Calendar.WeekendCalendar objects.

Server-side example for adding days:

Example

1
2
// Gets the date and time one day from now.
var currentDate = $Calendar.AddDays(DateTimeOffset.now, 1);

Client-side example for adding days (asynchronous):

Example

1
2
// Adds 2 days to the current date and time asynchronously.
var newDate = await $Calendar.AddDaysAsync(DateTimeOffset.now, 2);

Capabilities

Presets

Calendar Queries

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