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#
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#
pub struct ZoneBundleA 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#
impl ZoneBundleAssociated function fromBytes#
pub effect fn fromBytes(data: &[u8]) -> ZoneBundle ! ZoneLookupError | OutOfMemoryError ? &mut AllocatorReturns a provider over a copy of the bundle data.
Errors#
ZoneLookupErrorwith the reasonInvalidDataifdatais not a bundle or one of its tables points outside the data.OutOfMemoryErrorif theAllocatorcannot supply the copy.
Associated function fromOwned#
pub effect fn fromOwned(data: Bytes) -> ZoneBundle ! ZoneLookupErrorReturns a provider over the bundle data, which it takes over without a copy.
Errors#
ZoneLookupErrorwith the reasonInvalidDataifdatais not a bundle or one of its tables points outside the data.
Method windowsZone#
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#
pub fn nameCount(self: &Self) -> usizeReturns the number of zone names in the bundle, with the links.
Method release#
pub fn release(self: &Self) -> &[u8]Returns the name of the release of the time zone database, such as 2026b.
Implementation TimeZones for ZoneBundle#
impl TimeZones for ZoneBundleOperation zoneBytes#
zoneBytes: ZoneBundle.zoneBytesOperation names#
names: ZoneBundle.namesOperation version#
version: ZoneBundle.versionCategory: 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.