Modules · Data · Calendar

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

Types

Calendar.Date

A calendar day as a year, month and day. It also groups the date operations.

Fields

FieldTypeDescription
yearMaths.IntegerThe year (defaults to 2000).
monthMaths.IntegerThe month, 1 to 12 (defaults to 1).
dayMaths.IntegerThe 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 day
A record of three integer fields.

Example

LET Calendar.Date launch = Calendar.Date.Data 2024 1 15
Constructs 15 January 2024 as a reactive date.

Calendar.DateTime

A combined date and time. It also groups the date-time operations.

Fields

FieldTypeDescription
dateCalendar.DateThe date component.
timeCalendar.TimeThe time component.

Definition

TYPE Calendar.DateTime
  FIELD Calendar.Date date
  FIELD Calendar.Time time
A record pairing a date with a time.

Example

LET Calendar.DateTime meeting = Calendar.DateTime.Data launch noon
Combines a date and a time into one value.

Calendar.Time

A time of day, or a duration, held as a total number of seconds. It also groups the time operations.

Fields

FieldTypeDescription
totalSecondsMaths.RealThe number of seconds, measured from midnight (defaults to 0).

Definition

TYPE Calendar.Time
  FIELD Maths.Real totalSeconds
A record of a single real field.

Example

LET Calendar.Time noon = Calendar.Time.Data 43200.0
Noon, twelve hours of seconds past midnight.

Functions

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.CurrentYear
Reads today's year; it updates as the clock advances.

Calendar.Date.Data

Builds a date from a year, month and day.

Parameters

NameTypeDescription
yearMaths.IntegerThe year.
monthMaths.IntegerThe month, 1 to 12.
dayMaths.IntegerThe day of the month.

Returns

Returns Calendar.Date — a date carrying the given fields.

Example

LET Calendar.Date birthday = Calendar.Date.Data 1990 7 4
Constructs 4 July 1990.

Calendar.Date.FromJson

Reads a date back from a JSON value.

Parameters

NameTypeDescription
jsonUnionCode.Language.Json.ValueThe 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

NameTypeDescription
optionalJsonUnionCollection.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

NameTypeDescription
dataCalendar.DateThe 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

NameTypeDescription
dataCalendar.DateThe 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

NameTypeDescription
dataCalendar.DateThe date to read.

Returns

Returns Maths.Integer — the year of data.

Example

LET Maths.Integer year = Calendar.Date.GetYear birthday
Extracts the year from a date.

Calendar.Date.MonthName

The English name of a month number.

Parameters

NameTypeDescription
monthMaths.IntegerThe 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
Yields "July".

Calendar.Date.ToJson

Serialises a date to a JSON value.

Parameters

NameTypeDescription
dataCalendar.DateThe 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 birthday
Converts a date to JSON for storage or transport.

Calendar.DateTime.Data

Combines a date and a time into a date-time.

Parameters

NameTypeDescription
dateCalendar.DateThe date component.
timeCalendar.TimeThe time component.

Returns

Returns Calendar.DateTime — the paired date and time.

Example

LET Calendar.DateTime stamp = Calendar.DateTime.Data birthday noon
Pairs a date with a time of day.

Calendar.DateTime.FromJson

Reads a date-time back from a JSON value.

Parameters

NameTypeDescription
jsonUnionCode.Language.Json.ValueThe 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

NameTypeDescription
optionalJsonUnionCollection.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

NameTypeDescription
dataCalendar.DateTimeThe 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

NameTypeDescription
dataCalendar.DateTimeThe 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

NameTypeDescription
dataCalendar.DateTimeThe 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

NameTypeDescription
totalSecondsMaths.RealSeconds past midnight, or a duration in seconds.

Returns

Returns Calendar.Time — a time holding totalSeconds.

Example

LET Calendar.Time lunch = Calendar.Time.Data 43200.0
Noon, twelve hours after midnight.

Calendar.Time.FromJson

Reads a time back from a JSON value.

Parameters

NameTypeDescription
jsonUnionCode.Language.Json.ValueThe 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

NameTypeDescription
optionalJsonUnionCollection.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

NameTypeDescription
dataCalendar.TimeThe time to read.

Returns

Returns Maths.Real — the seconds held by data.

Calendar.Time.ToJson

Serialises a time to a JSON value.

Parameters

NameTypeDescription
dataCalendar.TimeThe time to serialise.

Returns

Returns Code.Language.Json.Value — an object with a totalSeconds field.