Time zones v0.1.0
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.
Fields
| Name | Type | Description |
|---|---|---|
offset | UtcOffset | The offset from UTC. |
daylight | bool | Whether this is daylight-saving time. |
abbreviation | char8[..] | 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.
Cases
| Name | Value | Description |
|---|---|---|
Unique | 0 | The local time happened once. |
Ambiguous | 1 | The local time happened twice, as clocks fell back over it. |
Skipped | 2 | The 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.
Fields
| Name | Type | Description |
|---|---|---|
kind | LocalTimeKind | What the local time is in the zone. |
earlier | Timestamp | The earlier candidate moment. |
later | Timestamp | The 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.
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.
| Name | Type | Description |
|---|---|---|
allocator | Allocator | what the zone is kept in |
name | char8[..] | the zone's name, such as Europe/Paris |
Returns: the zone, or fails with NotFound, InvalidName or InvalidData
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.
| Name | Type | Description |
|---|---|---|
allocator | Allocator | what the zone is kept in |
Returns: the zone, or fails when the system's setting cannot be read
Utc
pub func Utc(allocator: Allocator) -> TimeZone ! TimeZoneError
UTC, which has no offset and never changes.
| Name | Type | Description |
|---|---|---|
allocator | Allocator | what the zone is kept in |
Returns: the zone, or fails when the allocator refused
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.
| Name | Type | Description |
|---|---|---|
allocator | Allocator | what the zone is kept in |
name | char8[..] | what to call the zone |
rule | char8[..] | the rule |
Returns: the zone, or fails with InvalidRule
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.
| Name | Type | Description |
|---|---|---|
allocator | Allocator | what the zone is kept in |
name | char8[..] | what to call the zone, such as Europe/Kyiv |
data | byte[..] | the TZif data |
Returns: the zone, or fails with InvalidData
Methods
Name
pub func Name(self: &TimeZone) -> char8[..]
The zone's name.
Returns: the name it was given or loaded under
StateAt
pub func StateAt(
self: &TimeZone,
moment: Timestamp
) -> ZoneState
The local time the zone keeps at moment.
| Name | Type | Description |
|---|---|---|
moment | Timestamp | the moment |
Returns: its offset, whether it is daylight time, and its abbreviation
OffsetAt
pub func OffsetAt(
self: &TimeZone,
moment: Timestamp
) -> UtcOffset
The zone's offset from UTC at moment.
| Name | Type | Description |
|---|---|---|
moment | Timestamp | the moment |
Returns: the offset
ToLocal
pub func ToLocal(
self: &TimeZone,
moment: Timestamp
) -> OffsetDateTime
The local date and time moment is in the zone, with its offset.
| Name | Type | Description |
|---|---|---|
moment | Timestamp | the moment |
Returns: the local date, time and offset
Resolve
pub func Resolve(
self: &TimeZone,
local: DateTime
) -> LocalTime
The moments the local date and time local stands for in the zone.
| Name | Type | Description |
|---|---|---|
local | DateTime | a date and time on the zone's clocks |
Returns: whether it happened once, twice or never, and the candidate moments