Time zones v0.1.0

Source
A place's rules: loading them, and converting between UTC and local time.

ZoneState

pub struct ZoneState {
    pub offset: UtcOffset;
    pub daylight: bool;
    pub abbreviation: char8[..];
}

The local time a zone keeps at a moment: its offset, whether it is daylight time, and its abbreviation. Copy. The abbreviation is a view of the zone's own text, valid while the zone lives.

Source

Fields

NameTypeDescription
offsetUtcOffsetThe offset from UTC.
daylightboolWhether this is daylight-saving time.
abbreviationchar8[..]The abbreviation, such as CEST, or a numeric one such as +03.

LocalTimeKind

pub enum LocalTimeKind: uint8 {
    Unique = 0,
    Ambiguous = 1,
    Skipped = 2
}

What a local date and time is in a zone. Copy.

Source

Cases

NameValueDescription
Unique0The local time happened once.
Ambiguous1The local time happened twice, as clocks fell back over it.
Skipped2The local time never happened, as clocks sprang forward over it.

LocalTime

pub struct LocalTime {
    pub kind: LocalTimeKind;
    pub earlier: Timestamp;
    pub later: Timestamp;
}

The moments a local date and time stands for in a zone. Copy. For a unique time both moments are the same. For an ambiguous one they are its first and second occurrence. For a skipped one they are what it would mean under the offset after the change and before it; Later is the one most programs want, as it keeps the wall-clock distance from the hour before.

Source

Fields

NameTypeDescription
kindLocalTimeKindWhat the local time is in the zone.
earlierTimestampThe earlier candidate moment.
laterTimestampThe later candidate moment.

TimeZone

pub struct TimeZone {
    // private fields
}

A time zone, built from a TZif file, a POSIX rule, or the system's settings. Not copied.

Source

Associated functions

Load

pub func Load(
    allocator: Allocator,
    name: char8[..]
) -> TimeZone ! TimeZoneError

Loads the zone named name from the tz database: from the directory TZDIR names, or else, on the Unix systems, from the directories the database is kept in.

NameTypeDescription
allocatorAllocatorwhat the zone is kept in
namechar8[..]the zone's name, such as Europe/Paris

Returns: the zone, or fails with NotFound, InvalidName or InvalidData

Source

Local

pub func Local(allocator: Allocator) -> TimeZone ! TimeZoneError

The zone the system is set to. On the Unix systems that is the one TZ gives, as a zone name, a file path after : or a POSIX rule, or else the one in /etc/localtime. On Windows it is the system's zone, as rules for its standard and daylight time, which describe the current year's practice and so not the zone's history.

NameTypeDescription
allocatorAllocatorwhat the zone is kept in

Returns: the zone, or fails when the system's setting cannot be read

Source

Utc

pub func Utc(allocator: Allocator) -> TimeZone ! TimeZoneError

UTC, which has no offset and never changes.

NameTypeDescription
allocatorAllocatorwhat the zone is kept in

Returns: the zone, or fails when the allocator refused

Source

FromRule

pub func FromRule(
    allocator: Allocator,
    name: char8[..],
    rule: char8[..]
) -> TimeZone ! TimeZoneError

A zone kept by the POSIX TZ rule rule, such as EST5EDT,M3.2.0,M11.1.0.

NameTypeDescription
allocatorAllocatorwhat the zone is kept in
namechar8[..]what to call the zone
rulechar8[..]the rule

Returns: the zone, or fails with InvalidRule

Source

FromTzif

pub func FromTzif(
    allocator: Allocator,
    name: char8[..],
    data: byte[..]
) -> TimeZone ! TimeZoneError

A zone read from TZif data, the format of the files in a time-zone directory. Versions 1 to 4 are read; from version 2 on, the 64-bit history and the footer rule are used. Leap-second records are skipped, so a zone from the right/ directories reads as its posix/ twin.

NameTypeDescription
allocatorAllocatorwhat the zone is kept in
namechar8[..]what to call the zone, such as Europe/Kyiv
databyte[..]the TZif data

Returns: the zone, or fails with InvalidData

Source

Methods

Name

pub func Name(self: &TimeZone) -> char8[..]

The zone's name.

Returns: the name it was given or loaded under

Source

StateAt

pub func StateAt(
    self: &TimeZone,
    moment: Timestamp
) -> ZoneState

The local time the zone keeps at moment.

NameTypeDescription
momentTimestampthe moment

Returns: its offset, whether it is daylight time, and its abbreviation

Source

OffsetAt

pub func OffsetAt(
    self: &TimeZone,
    moment: Timestamp
) -> UtcOffset

The zone's offset from UTC at moment.

NameTypeDescription
momentTimestampthe moment

Returns: the offset

Source

ToLocal

pub func ToLocal(
    self: &TimeZone,
    moment: Timestamp
) -> OffsetDateTime

The local date and time moment is in the zone, with its offset.

NameTypeDescription
momentTimestampthe moment

Returns: the local date, time and offset

Source

Resolve

pub func Resolve(
    self: &TimeZone,
    local: DateTime
) -> LocalTime

The moments the local date and time local stands for in the zone.

NameTypeDescription
localDateTimea date and time on the zone's clocks

Returns: whether it happened once, twice or never, and the candidate moments

Source