TimeZone v0.1.0

Source
Time zones: the tz database, POSIX rules, the local zone, and local times that happen twice or never

Installation

Add TimeZone to the [Dependencies] table of your package's Rux.toml:

[Dependencies]
TimeZone = { Namespace = "Rux", Version = "0.1.0" }

Standard packages are declared by hand: the registry does not serve them, so rux add Rux/TimeZone cannot add them.

Dependencies

Guide

What it provides

ModuleCovers
ZoneTimeZone with FromTzif, FromRule, Utc, StateAt, OffsetAt, ToLocal and Resolve; ZoneState and LocalTime
SystemTimeZone::Load by tz database name, and TimeZone::Local
ErrorTimeZoneError

The module names describe where each declaration comes from; they are not part of an import path.

Example

import Allocator::SystemAllocator;
import Time::Timestamp;
import TimeZone::{ TimeZone, TimeZoneError };

func KyivOffset() -> int32 ! TimeZoneError {
    let zone = TimeZone::Load(SystemAllocator(), "Europe/Kyiv")?;
    return zone.OffsetAt(Timestamp::Now()).seconds;
}

Design

A zone is the tz database's history of the offsets it kept and when they changed, read from a TZif file as RFC 8536 describes it, followed by the POSIX TZ rule it keeps after its last listed change; or a rule alone. Versions 1 to 4 of TZif are read, using the 64-bit history and the footer rule from version 2 on; leap-second records are skipped, so the right/ zones read as their posix/ twins. Rules take quoted abbreviations such as <+0330>, offsets with minutes and seconds, the Jn, n and Mm.w.d dates and the extended change times of TZif version 3, and work south of the equator, where daylight time spans the new year.

StateAt gives a moment's offset, whether it is daylight time, and its abbreviation; ToLocal gives its local date and time. Resolve goes the other way, and says whether a local date and time happened once, twice as clocks fell back, or never as they sprang forward, with both candidate moments.

Load looks a zone up by name in the directory TZDIR names, or else in the directories the Unix systems keep the database in. Names that leave the directory are refused. Windows keeps no such directory, so there a zone loads only from a TZDIR the program provides. Local reads TZ or /etc/localtime on the Unix systems; on Windows it reads the system's zone as rules for standard and daylight time, which describe current practice rather than the zone's history.

Index

Types

NameSummary
TimeZoneErrorWhy a time zone could not be loaded or built.
ZoneStateThe local time a zone keeps at a moment: its offset, whether it is daylight time, and its abbreviation.
LocalTimeKindWhat a local date and time is in a zone.
LocalTimeThe moments a local date and time stands for in a zone.
TimeZoneA time zone, built from a TZif file, a POSIX rule, or the system's settings.