Calendar
Dates, times and date-times. Calendar provides three plain data types —
Calendar.Date for a calendar day,
Calendar.Time for a time of day (or duration) held as
seconds, and Calendar.DateTime pairing the two. Each
type doubles as a pseudo-module that groups its own operations: a constructor, field accessors,
and JSON conversion. Every value is reactive, so a derived year or a formatted month name
recomputes whenever the date it reads changes.
Contents
Types
Functions
- Calendar.CurrentDay
- Calendar.CurrentMonth
- Calendar.CurrentYear
- Calendar.Date.Data
- Calendar.Date.FromJson
- Calendar.Date.FromJsonOptional
- Calendar.Date.GetDay
- Calendar.Date.GetMonth
- Calendar.Date.GetYear
- Calendar.Date.MonthName
- Calendar.Date.ToJson
- Calendar.DateTime.Data
- Calendar.DateTime.FromJson
- Calendar.DateTime.FromJsonOptional
- Calendar.DateTime.GetDate
- Calendar.DateTime.GetTime
- Calendar.DateTime.ToJson
- Calendar.Time.Data
- Calendar.Time.FromJson
- Calendar.Time.FromJsonOptional
- Calendar.Time.GetTotalSeconds
- Calendar.Time.ToJson
Types
Calendar.Date
A calendar day as a year, month and day. It also groups the date operations.
Fields
| Field | Type | Description |
|---|---|---|
year | Maths.Integer | The year (defaults to 2000). |
month | Maths.Integer | The month, 1 to 12 (defaults to 1). |
day | Maths.Integer | The day of the month, 1 to 31 (defaults to 1). |
Definition
TYPE Calendar.Date
FIELD Maths.Integer year
FIELD Maths.Integer month
FIELD Maths.Integer dayExample
LET Calendar.Date launch = Calendar.Date.Data 2024 1 15Calendar.DateTime
A combined date and time. It also groups the date-time operations.
Fields
| Field | Type | Description |
|---|---|---|
date | Calendar.Date | The date component. |
time | Calendar.Time | The time component. |
Definition
TYPE Calendar.DateTime
FIELD Calendar.Date date
FIELD Calendar.Time timeExample
LET Calendar.DateTime meeting = Calendar.DateTime.Data launch noonCalendar.Time
A time of day, or a duration, held as a total number of seconds. It also groups the time operations.
Fields
| Field | Type | Description |
|---|---|---|
totalSeconds | Maths.Real | The number of seconds, measured from midnight (defaults to 0). |
Definition
TYPE Calendar.Time
FIELD Maths.Real totalSecondsExample
LET Calendar.Time noon = Calendar.Time.Data 43200.0Functions
Calendar.CurrentDay
The current day of the month from the system clock.
Returns
Returns Maths.Integer — the current day of the month.
Calendar.CurrentMonth
The current month from the system clock.
Returns
Returns Maths.Integer — the current month, 1 to 12.
Calendar.CurrentYear
The current year from the system clock.
Returns
Returns Maths.Integer — the current calendar year.
Example
LET Maths.Integer thisYear = Calendar.CurrentYearCalendar.Date.Data
Builds a date from a year, month and day.
Parameters
| Name | Type | Description |
|---|---|---|
year | Maths.Integer | The year. |
month | Maths.Integer | The month, 1 to 12. |
day | Maths.Integer | The day of the month. |
Returns
Returns Calendar.Date — a date carrying the given fields.
Example
LET Calendar.Date birthday = Calendar.Date.Data 1990 7 4Calendar.Date.FromJson
Reads a date back from a JSON value.
Parameters
| Name | Type | Description |
|---|---|---|
jsonUnion | Code.Language.Json.Value | The JSON object to read. |
Returns
Returns Calendar.Date — the date parsed from the JSON, filling missing fields with defaults.
Calendar.Date.FromJsonOptional
Reads a date from an optional JSON value, propagating absence.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonUnion | Collection.Optional(Code.Language.Json.Value) | The JSON value, if present. |
Returns
Returns Collection.Optional(Calendar.Date) — the parsed date, or nothing when the input is absent.
Calendar.Date.GetDay
Reads the day field of a date.
Parameters
| Name | Type | Description |
|---|---|---|
data | Calendar.Date | The date to read. |
Returns
Returns Maths.Integer — the day of the month of data.
Calendar.Date.GetMonth
Reads the month field of a date.
Parameters
| Name | Type | Description |
|---|---|---|
data | Calendar.Date | The date to read. |
Returns
Returns Maths.Integer — the month of data, 1 to 12.
Calendar.Date.GetYear
Reads the year field of a date.
Parameters
| Name | Type | Description |
|---|---|---|
data | Calendar.Date | The date to read. |
Returns
Returns Maths.Integer — the year of data.
Example
LET Maths.Integer year = Calendar.Date.GetYear birthdayCalendar.Date.MonthName
The English name of a month number.
Parameters
| Name | Type | Description |
|---|---|---|
month | Maths.Integer | The month number, 1 to 12. |
Returns
Returns Text — the English month name, or an empty text when the number is out of range.
Example
LET Text label = Calendar.Date.MonthName 7"July".Calendar.Date.ToJson
Serialises a date to a JSON value.
Parameters
| Name | Type | Description |
|---|---|---|
data | Calendar.Date | The date to serialise. |
Returns
Returns Code.Language.Json.Value — an object with year, month and day fields.
Example
LET Code.Language.Json.Value json = Calendar.Date.ToJson birthdayCalendar.DateTime.Data
Combines a date and a time into a date-time.
Parameters
| Name | Type | Description |
|---|---|---|
date | Calendar.Date | The date component. |
time | Calendar.Time | The time component. |
Returns
Returns Calendar.DateTime — the paired date and time.
Example
LET Calendar.DateTime stamp = Calendar.DateTime.Data birthday noonCalendar.DateTime.FromJson
Reads a date-time back from a JSON value.
Parameters
| Name | Type | Description |
|---|---|---|
jsonUnion | Code.Language.Json.Value | The JSON object to read. |
Returns
Returns Calendar.DateTime — the date-time parsed from the JSON.
Calendar.DateTime.FromJsonOptional
Reads a date-time from an optional JSON value, propagating absence.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonUnion | Collection.Optional(Code.Language.Json.Value) | The JSON value, if present. |
Returns
Returns Collection.Optional(Calendar.DateTime) — the parsed date-time, or nothing when the input is absent.
Calendar.DateTime.GetDate
Reads the date component of a date-time.
Parameters
| Name | Type | Description |
|---|---|---|
data | Calendar.DateTime | The date-time to read. |
Returns
Returns Calendar.Date — the date part of data.
Calendar.DateTime.GetTime
Reads the time component of a date-time.
Parameters
| Name | Type | Description |
|---|---|---|
data | Calendar.DateTime | The date-time to read. |
Returns
Returns Calendar.Time — the time part of data.
Calendar.DateTime.ToJson
Serialises a date-time to a JSON value.
Parameters
| Name | Type | Description |
|---|---|---|
data | Calendar.DateTime | The date-time to serialise. |
Returns
Returns Code.Language.Json.Value — an object holding the date and time.
Calendar.Time.Data
Builds a time from a total number of seconds.
Parameters
| Name | Type | Description |
|---|---|---|
totalSeconds | Maths.Real | Seconds past midnight, or a duration in seconds. |
Returns
Returns Calendar.Time — a time holding totalSeconds.
Example
LET Calendar.Time lunch = Calendar.Time.Data 43200.0Calendar.Time.FromJson
Reads a time back from a JSON value.
Parameters
| Name | Type | Description |
|---|---|---|
jsonUnion | Code.Language.Json.Value | The JSON object to read. |
Returns
Returns Calendar.Time — the time parsed from the JSON.
Calendar.Time.FromJsonOptional
Reads a time from an optional JSON value, propagating absence.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonUnion | Collection.Optional(Code.Language.Json.Value) | The JSON value, if present. |
Returns
Returns Collection.Optional(Calendar.Time) — the parsed time, or nothing when the input is absent.
Calendar.Time.GetTotalSeconds
Reads the total-seconds field of a time.
Parameters
| Name | Type | Description |
|---|---|---|
data | Calendar.Time | The time to read. |
Returns
Returns Maths.Real — the seconds held by data.
Calendar.Time.ToJson
Serialises a time to a JSON value.
Parameters
| Name | Type | Description |
|---|---|---|
data | Calendar.Time | The time to serialise. |
Returns
Returns Code.Language.Json.Value — an object with a totalSeconds field.