Module: time.time

Source: ./time/time.reef


Overview

time/time - Time and date functions

Provides functions for working with time and dates using the Gregorian calendar. Times are represented as Unix timestamps (seconds since 1970-01-01 00:00:00 UTC). Date/time extraction functions return UTC values. time_offset_at / time_local_offset_seconds give the host TZ offset (seconds east of UTC, DST included) via libc localtime.

Usage: import time.time let now = time_now() let year = time_year(now) let formatted = time_format_iso(now)


Functions

fn time_now(): int

fn time_now_millis(): int

fn time_subsec_millis(): int

fn time_offset_at(timestamp: int): int

fn time_local_offset_seconds(): int

fn is_leap_year(year: int): bool

fn days_in_month(year: int, month: int): option.Option[int]

fn month_length(year: int, month: int): int

Length of a month already known to be 1..12. Every caller below either iterates a while month <= 12 loop from 1 or validates explicitly first, so the unwrap cannot fire; if that ever stops being true it PANICS rather than silently contributing 0 to a day sum, which is precisely the failure the old sentinel produced.

fn days_in_year(year: int): int

Days in year

fn timestamp_to_days(timestamp: int): int

Internal: Get total days since epoch and remaining seconds Returns days in first element, remaining seconds in internal state

fn timestamp_seconds_of_day(timestamp: int): int

fn days_to_year_and_yday(total_days: int, out_yday: [int]): int

Calculate year and day-of-year from days since epoch Returns year, stores day-of-year internally for next call

fn time_year(timestamp: int): int

fn time_yearday(timestamp: int): int

fn time_month(timestamp: int): int

fn time_day(timestamp: int): int

fn time_hour(timestamp: int): int

fn time_minute(timestamp: int): int

fn time_second(timestamp: int): int

fn time_weekday(timestamp: int): int

fn time_make(year_in: int, month_in: int, day: int, hour: int, minute: int, second: int): int

============================================================================ Date Creation

fn digit_char(n: int): char

fn time_format_iso(timestamp: int): string

Format as ISO 8601: YYYY-MM-DDTHH:MM:SS

fn time_format_date(timestamp: int): string

Format as date: YYYY-MM-DD

fn time_format_time(timestamp: int): string

Format as time: HH:MM:SS

fn time_add_seconds(timestamp: int, seconds: int): int

fn time_add_minutes(timestamp: int, minutes: int): int

fn time_add_hours(timestamp: int, hours: int): int

fn time_add_days(timestamp: int, days: int): int

fn time_diff(t1: int, t2: int): int

fn iso_read_digits(s: string, start: int, count: int, slen: int, out: [int]): bool

Read exactly count digits starting at index start. Returns the parsed value via out[0] and true on success, false on insufficient or non-digit input.

fn time_parse_iso(s: string): result.Result[int, error.Error]


Generated by reefc doc