Module: time.date
Source: ./time/date.reef
Overview
time/date - Date handling functions
Provides functions for working with dates using the Gregorian calendar. Dates are represented as days since the Unix epoch (1970-01-01). This is more efficient than timestamps for pure date operations.
Usage: import time.date let today = date_today() let year = date_year(today) let tomorrow = date_add_days(today, 1) let formatted = date_format(today)
Functions
fn is_leap_year(year: int): bool
fn month_length(year: int, month: int): int
Length of a month that is ALREADY KNOWN to be in 1..12.
PRECONDITION: 1 <= month <= 12, and every caller in this module meets it --
date_parse validates explicitly immediately before calling; date_month and
date_day iterate a while month <= 12 loop from 1; date_make and
date_add_months normalise into range first; date_add_years,
date_start_of_month and date_end_of_month take the month from date_month(),
which cannot return out of range. The checked public entry point is
days_in_month() below.
The final arm is month 12, so the chain covers exactly 1..12 with no sentinel arm to mistake for an answer.
fn days_in_month(year: int, month: int): option.Option[int]
Days in the given month, or None if the month is not 1..12.
ROADMAP §8.3 / C16: this returned a 0 SENTINEL for month > 12, and the module's own date_make carried a comment naming it "the C16 violation" and working around it rather than fixing it -- measured there, date_make(2024, 13, 1) and date_make(2024, 14, 1) BOTH returned 20089, because the sentinel silently contributed nothing to the day sum.
There is deliberately NO days_in_month_or twin. _or suits a lookup whose
miss is ordinary (035_ERROR_HANDLING.md:421-461); here None means the month
argument is invalid, and defaulting would resume the arithmetic that the
sentinel already made wrong.
fn days_in_year(year: int): int
fn date_today(): int
fn date_make(year_in: int, month_in: int, day: int): int
fn date_parse(s: string): result.Result[int, error.Error]
Parse strict ISO date YYYY-MM-DD. Rejects any deviation: missing zero-pads, non-dash separators, non-digit chars, trailing text, or out-of-range values.
fn days_to_year_yday(total_days: int, out_yday: [int]): int
Internal: convert days to year and day-of-year
fn date_year(date: int): int
fn date_yearday(date: int): int
fn date_month(date: int): int
fn date_day(date: int): int
fn date_weekday(date: int): int
fn date_add_days(date: int, days: int): int
fn date_add_weeks(date: int, weeks: int): int
fn date_add_months(date: int, months: int): int
fn date_add_years(date: int, years: int): int
fn date_diff_days(date1: int, date2: int): int
fn date_before(date1: int, date2: int): bool
fn date_after(date1: int, date2: int): bool
fn date_equal(date1: int, date2: int): bool
fn digit_char(n: int): char
fn date_format(date: int): string
Format as ISO: YYYY-MM-DD
fn date_format_us(date: int): string
Format as US: MM/DD/YYYY
fn date_format_eu(date: int): string
Format as EU: DD.MM.YYYY
fn date_format_long(date: int): string
Format as long: Month DD, YYYY
fn weekday_name(weekday: int): string
fn weekday_name_short(weekday: int): string
fn month_name(month: int): string
fn month_name_short(month: int): string
fn date_week_of_year(date: int): int
ISO week number (1-53) Week 1 is the week containing the first Thursday of the year
fn date_start_of_week(date: int): int
Get Sunday of the current week
fn date_start_of_month(date: int): int
Get first day of the month
fn date_end_of_month(date: int): int
Get last day of the month
fn date_to_timestamp(date: int): int
Convert date to Unix timestamp (midnight UTC)
fn timestamp_to_date(timestamp: int): int
Convert Unix timestamp to date
Generated by reefc doc