Skip to content

Date

[Source]

A proleptic Gregorian calendar date: year, month, day.

Year range: - Default: 1970..=9999 (matches default tzdata coverage). - With -D HISTORICAL_TZ: 1..=9999 (matches widened tzdata coverage back through pre-1900 LMT-era zones).

Calendar math (leap years, day-of-week, days-in-month, day-of-year, arithmetic) uses the proleptic Gregorian rule for all years in range, even those preceding regional Gregorian adoption (1582 onward).

class val Date

Constructors

create

[Source]

Construct a date. Errors if year is outside the supported range, or if (month, day) is not a real calendar date (e.g. Feb 30, Apr 31, Feb 29 of a non-leap year).

new val create(
  year': I16 val,
  month': U8 val,
  day': U8 val)
: Date val^ ?

Parameters

  • year': I16 val
  • month': U8 val
  • day': U8 val

Returns


epoch

[Source]

1970-01-01 — non-partial because the epoch date is always valid in every supported configuration. Used for stubs and as a safe default.

new val epoch()
: Date val^

Returns


Public Functions

year

[Source]

fun val year()
: I16 val

Returns


month

[Source]

fun val month()
: U8 val

Returns


day

[Source]

fun val day()
: U8 val

Returns


is_leap_year

[Source]

True if this date's year is leap under the proleptic Gregorian rule.

fun val is_leap_year()
: Bool val

Returns


days_in_month

[Source]

Number of days in this date's month (28..=31), accounting for leap year.

fun val days_in_month()
: U8 val

Returns


day_of_week

[Source]

Day-of-week via Zeller's congruence (proleptic Gregorian).

fun val day_of_week()
: DayOfWeek

Returns


day_of_year

[Source]

Ordinal day within the year: 1 for Jan 1, up to 365 or 366.

fun val day_of_year()
: U16 val

Returns


days_since_epoch

[Source]

Days from 1970-01-01. Negative for pre-epoch dates.

fun val days_since_epoch()
: I32 val

Returns


compare

[Source]

fun val compare(
  other: Date val)
: Compare

Parameters

Returns


eq

[Source]

fun val eq(
  other: Date val)
: Bool val

Parameters

Returns


ne

[Source]

fun val ne(
  other: Date val)
: Bool val

Parameters

Returns


lt

[Source]

fun val lt(
  other: Date val)
: Bool val

Parameters

Returns


le

[Source]

fun val le(
  other: Date val)
: Bool val

Parameters

Returns


gt

[Source]

fun val gt(
  other: Date val)
: Bool val

Parameters

Returns


ge

[Source]

fun val ge(
  other: Date val)
: Bool val

Parameters

Returns


add_days

[Source]

Return a new Date n days after this one (negative for past). Errors if the result is outside the supported year range.

fun val add_days(
  n: I32 val)
: (Date val | ArithmeticError)

Parameters

Returns


add_months

[Source]

Return a new Date n months after this one (negative for past). On month-shift overflow (e.g. Jan 31 + 1 month), policy decides between clamping (Feb 28/29) and rejecting (ArithmeticPolicyReject).

fun val add_months(
  n: I32 val,
  policy: OverflowPolicy)
: (Date val | ArithmeticError)

Parameters

Returns


add_period

[Source]

Apply months and days from p. The nanos component is ignored because Date has no time-of-day to apply it to (pair with TimeOfDay or use ZonedDateTime for sub-day arithmetic).

fun val add_period(
  p: Period val,
  policy: OverflowPolicy)
: (Date val | ArithmeticError)

Parameters

Returns


string

[Source]

ISO 8601 date format: YYYY-MM-DD. Negative years prefixed with '-'.

fun val string()
: String iso^

Returns