gizlang:time
calendar dates in UTC from milliseconds since 1970-01-01, as JavaScript's Date keeps them (proleptic Gregorian; System.time() is now).
import * as Time from "gizlang:time";Types
DateTime
type DateTime = { year: i64; month: i64; day: i64; hour: i64; minute: i64; second: i64; millisecond: i64; }A civil date and time, in UTC or in the zone that made it.
year:i64month:i64day:i64hour:i64minute:i64second:i64millisecond:i64
CivilDate
type CivilDate = { year: i64; month: i64; day: i64; }A civil date without a time: what a day number (days since 1970-01-01) is.
year:i64month:i64day:i64
TimeError
type TimeError = { message: string; code: i64; }A time failure: what is wrong and a code.
message:stringcode:i64
Zone
type ZoneOffsets are seconds east of UTC. A Zone is owned data, independent of its Dir.
Opaque: create and use it through this module's functions.
Functions
daysFromCivil
function daysFromCivil(year: i64, month: i64, day: i64): i64Days since 1970-01-01 of a civil date, and back (H. Hinnant's algorithms): the one calendar every date in Gizlang goes through, GizDB's SQL dates too.
Effects: fail.
dateOfDay
function dateOfDay(days: i64): CivilDateThe civil date of a day number (days since 1970-01-01).
Effects: fail.
utc
function utc(ms: i64): DateTimeThe UTC date and time of MS, milliseconds since 1970-01-01 UTC.
Effects: fail.
utcMs
function utcMs(d: DateTime): i64The milliseconds since 1970-01-01 UTC of the UTC date and time D.
Effects: fail.
weekday
function weekday(ms: i64): i640 is Sunday, as JavaScript's getUTCDay.
Effects: fail.
weekdayOfDay
function weekdayOfDay(day: i64): i64The weekday of DAY (days since 1970-01-01, a Thursday): 0 is Sunday.
Effects: fail.
dayNames
function dayNames(long: bool): Vec<string>The English names of the days, Sunday first (weekday's order): "Sun" or, when LONG, "Sunday".
Effects: fail.
monthNames
function monthNames(long: bool): Vec<string>The English names of the months, January first: "Jan" or, when LONG, "January".
Effects: fail.
iso
function iso(ms: i64): string2026-10-09T03:24:17.304Z, as JavaScript's toISOString: years outside 0 to
9999 take a sign and six digits (+010901-04-24...).
Effects: fail.
parseZone
function parseZone(data: bytes): Zone throws TimeErrorThe zone of a TZif file's bytes (RFC 8536, versions 1-3, no leap seconds): data a program carries, as GizDB carries the tz database. O(bytes), allocating the transition, type and offset vectors once.
Effects: fail.
posixZone
function posixZone(text: string, rules: string): Zone throws TimeErrorThe zone a POSIX TZ string names ("CST6CDT,M3.2.0,M11.1.0", "<-01:30>+01:30"; offsets west of UTC). A daylight
name without rules takes rules ("M3.2.0,M11.1.0", as PostgreSQL's posixrules gives them).
Effects: fail.
zone
function zone(dir: Dir, name: string): Zone throws TimeErrorRead once through the supplied directory capability; O(file bytes), allocating transition/type/offset vectors once. No global IO or cache; queries borrow them.
Effects: fail, io.
monthDays
function monthDays(year: i64, month: i64): i64The number of days in MONTH (1 to 12) of YEAR.
Effects: fail.
addDays
function addDays(d: DateTime, days: i64): DateTime requires valid(d) && days> = -MAX_DAY_ADJUSTMENT && days <= MAX_DAY_ADJUSTMENTCalendar operations preserve the clock; apply Zone.instant to resolve DST.
Effects: fail.
addMonths
function addMonths(d: DateTime, months: i64): DateTime requires valid(d) && months> = -MAX_MONTH_ADJUSTMENT && months <= MAX_MONTH_ADJUSTMENTD moved by MONTHS months; a day past the end of the month becomes its last day.
Effects: fail.
addYears
function addYears(d: DateTime, years: i64): DateTime requires valid(d) && years> = -MAX_YEAR_ADJUSTMENT && years <= MAX_YEAR_ADJUSTMENTD moved by YEARS years; February 29 becomes February 28 in a year that is not a leap year.
Effects: fail.
daysBetween
function daysBetween(from: DateTime, to: DateTime): i64 requires valid(from) && valid(to)Signed civil-date distance (to - from), independent of time-of-day and DST.
Effects: fail.
parseIso
function parseIso(text: string): i64 throws TimeErrorExtended ISO calendar date-time, mandatory Z or ±HH:MM[:SS], 1-3 fraction digits.
Effects: fail.
Methods
Zone.offset
function Zone.offset(self: Zone, ms: i64): i64 requires ms> = -MAX_ZONE_INSTANT_MS && ms <= MAX_ZONE_INSTANT_MSO(log transitions), no allocation. TZif's type zero applies before the table.
Effects: fail.
Zone.abbreviation
function Zone.abbreviation(self: Zone, ms: i64): string requires ms> = -MAX_ZONE_INSTANT_MS && ms <= MAX_ZONE_INSTANT_MSThe zone's abbreviation in effect at ms ("KST", "PDT"), or "" when the zone has none.
Effects: fail.
Zone.local
function Zone.local(self: Zone, ms: i64): DateTimeThe local date and time in this zone of MS, milliseconds since 1970-01-01 UTC.
Effects: fail.
Zone.instant
function Zone.instant(self: Zone, d: DateTime): i64 throws TimeErrorO(types * log transitions); only a gap scans the table. No allocation.
Effects: fail.
Zone.iso
function Zone.iso(self: Zone, ms: i64): stringMS as ISO 8601 text in this zone, with its offset.
Effects: fail.
Constants
MILLISECONDS_PER_SECOND
const MILLISECONDS_PER_SECOND = 1000The number of milliseconds in one second: 1000.
MILLISECONDS_PER_MINUTE
const MILLISECONDS_PER_MINUTE = 60000The number of milliseconds in one minute: 60000.
MILLISECONDS_PER_HOUR
const MILLISECONDS_PER_HOUR = 3600000The number of milliseconds in one hour: 3600000.
MILLISECONDS_PER_DAY
const MILLISECONDS_PER_DAY = 86400000The number of milliseconds in one day: 86400000.
SECONDS_PER_MINUTE
const SECONDS_PER_MINUTE = 60The number of seconds in one minute: 60.
MINUTES_PER_HOUR
const MINUTES_PER_HOUR = 60The number of minutes in one hour: 60.
SECONDS_PER_HOUR
const SECONDS_PER_HOUR = 3600The number of seconds in one hour: 3600.
SECONDS_PER_DAY
const SECONDS_PER_DAY = 86400The number of seconds in one day: 86400.
MAX_ZONE_INSTANT_MS
const MAX_ZONE_INSTANT_MS = 9000000000000000000The most milliseconds of an instant that a zone conversion accepts.
MAX_DAY_ADJUSTMENT
const MAX_DAY_ADJUSTMENT = 365000000The most days that a date adjustment adds or subtracts.
MAX_MONTH_ADJUSTMENT
const MAX_MONTH_ADJUSTMENT = 12000000The most months that a date adjustment adds or subtracts.
MAX_YEAR_ADJUSTMENT
const MAX_YEAR_ADJUSTMENT = 1000000The most years that a date adjustment adds or subtracts.