TimeZone v0.1.0
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
Allocator0.1.0Collections0.1.0Core0.1.0FileSystem0.1.0Io0.1.0Path0.1.0Process0.1.0Time0.1.0Windows0.1.0 (Windows only)
Guide
What it provides
| Module | Covers |
|---|---|
Zone | TimeZone with FromTzif, FromRule, Utc, StateAt, OffsetAt, ToLocal and Resolve; ZoneState and LocalTime |
System | TimeZone::Load by tz database name, and TimeZone::Local |
Error | TimeZoneError |
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
| Name | Summary |
|---|---|
TimeZoneError | Why a time zone could not be loaded or built. |
ZoneState | The local time a zone keeps at a moment: its offset, whether it is daylight time, and its abbreviation. |
LocalTimeKind | What a local date and time is in a zone. |
LocalTime | The moments a local date and time stands for in a zone. |
TimeZone | A time zone, built from a TZif file, a POSIX rule, or the system's settings. |