silk.time.zones_bundle.

A TimeZones provider over the bytes of a time zone bundle: one file with every zone of a release of the IANA time zone database.

When to use#

Use ZoneBundle in a program that ships or downloads its own bundle, for example a newer release than the one inside the standard library. Use BundledTimeZones of silk.time.zones_bundled for the bundle that the standard library carries, and OsTimeZones of silk.time.zones_native for the zones of the operating system.

Details#

A bundle is the file that scripts/time/generate-tzdb of the Silk repository writes. It holds the names of all zones and links, one TZif file for each distinct zone, the name of the release, and the table that maps the zone names of Windows to IANA names. ZoneBundle.fromBytes checks the tables one time, and a lookup then reads only the entry and the TZif file of one zone.

Examples#

Read a zone from a bundle file#

silk
import silk.build.source { Source }
import silk.mem.allocator { Allocator, OutOfMemoryError }
import silk.core.effect { Effect }
import silk.time.zone { Zone }
import silk.time.zones { TimeZones, ZoneLookupError }
import silk.time.zones_bundle { ZoneBundle }

effect fn rome() -> Zone ! ZoneLookupError | OutOfMemoryError ? &mut Allocator {
  let mut zones = run ZoneBundle.fromBytes(Source.read("data/tzdb.bin"))
  return run TimeZones.zone("Europe/Rome") |> Effect.provideMut<TimeZones>(&mut zones)
}

Import as ZoneBundle with import silk.time.zones_bundle { ZoneBundle }.

Public declarations: 1.

ZoneBundle#

silk
pub struct ZoneBundle

A TimeZones provider over the bytes of one time zone bundle. It owns the bytes.

Details#

The provider gives every zone and link of the bundle, and UTC and fixed offsets as every provider does. Names are compared without letter case, and a zone has the name as the bundle spells it. ZoneBundle.windowsZone gives the IANA name for a zone name of Windows.

Implementation ZoneBundle#

silk
impl ZoneBundle

Associated function fromBytes#

silk
pub effect fn fromBytes(data: &[u8]) -> ZoneBundle ! ZoneLookupError | OutOfMemoryError ? &mut Allocator

Returns a provider over a copy of the bundle data.

Errors#

  • ZoneLookupError with the reason InvalidData if data is not a bundle or one of its tables points outside the data.

  • OutOfMemoryError if the Allocator cannot supply the copy.

Associated function fromOwned#

silk
pub effect fn fromOwned(data: Bytes) -> ZoneBundle ! ZoneLookupError

Returns a provider over the bundle data, which it takes over without a copy.

Errors#

  • ZoneLookupError with the reason InvalidData if data is not a bundle or one of its tables points outside the data.

Method windowsZone#

silk
pub fn windowsZone(self: &Self, name: &[u8]) -> Option<&[u8]>

Returns the IANA zone name for the zone name of Windows name, such as Europe/Berlin for W. Europe Standard Time, or None if the bundle does not list the name. Letter case does not matter.

Details#

The table is the one of the Unicode CLDR project, with the default zone of each Windows name.

Method nameCount#

silk
pub fn nameCount(self: &Self) -> usize

Returns the number of zone names in the bundle, with the links.

Method release#

silk
pub fn release(self: &Self) -> &[u8]

Returns the name of the release of the time zone database, such as 2026b.

Implementation TimeZones for ZoneBundle#

silk
impl TimeZones for ZoneBundle

Operation zoneBytes#

silk
zoneBytes: ZoneBundle.zoneBytes

Operation names#

silk
names: ZoneBundle.names

Operation version#

silk
version: ZoneBundle.version

Category: Time.

Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2, x86_64-pc-windows-msvc, wasm64-unknown-unknown.

View the source of this page