Date¶
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).
Constructors¶
create¶
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).
Parameters¶
Returns¶
- Date val^ ?
epoch¶
1970-01-01 — non-partial because the epoch date is always valid in every supported configuration. Used for stubs and as a safe default.
Returns¶
- Date val^
Public Functions¶
year¶
Returns¶
- I16 val
month¶
Returns¶
- U8 val
day¶
Returns¶
- U8 val
is_leap_year¶
True if this date's year is leap under the proleptic Gregorian rule.
Returns¶
- Bool val
days_in_month¶
Number of days in this date's month (28..=31), accounting for leap year.
Returns¶
- U8 val
day_of_week¶
Day-of-week via Zeller's congruence (proleptic Gregorian).
Returns¶
day_of_year¶
Ordinal day within the year: 1 for Jan 1, up to 365 or 366.
Returns¶
- U16 val
days_since_epoch¶
Days from 1970-01-01. Negative for pre-epoch dates.
Returns¶
- I32 val
compare¶
Parameters¶
- other: Date val
Returns¶
eq¶
Parameters¶
- other: Date val
Returns¶
- Bool val
ne¶
Parameters¶
- other: Date val
Returns¶
- Bool val
lt¶
Parameters¶
- other: Date val
Returns¶
- Bool val
le¶
Parameters¶
- other: Date val
Returns¶
- Bool val
gt¶
Parameters¶
- other: Date val
Returns¶
- Bool val
ge¶
Parameters¶
- other: Date val
Returns¶
- Bool val
add_days¶
Return a new Date n days after this one (negative for past).
Errors if the result is outside the supported year range.
Parameters¶
- n: I32 val
Returns¶
- (Date val | ArithmeticError)
add_months¶
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).
Parameters¶
- n: I32 val
- policy: OverflowPolicy
Returns¶
- (Date val | ArithmeticError)
add_period¶
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).
Parameters¶
- p: Period val
- policy: OverflowPolicy
Returns¶
- (Date val | ArithmeticError)
string¶
ISO 8601 date format: YYYY-MM-DD. Negative years prefixed with '-'.
Returns¶
- String iso^