silk.time.zones_bundled.

The time zone database that the standard library carries: a TimeZones provider with the same zones on every target.

When to use#

Provide BundledTimeZones when the result must not depend on the machine, or when the machine may have no zone files, as in a slim container. OsTimeZones of silk.time.zones_native already uses it on Windows, WASI, and browsers, where the system has no zone files, and PreferSystemTimeZones uses it when the system does not know a zone. Use ZoneBundle of silk.time.zones_bundle for a bundle that the program supplies.

Details#

The data is one release of the IANA time zone database, compiled to TZif files, with every zone and link. The program holds it compressed, about 60 KB, and only a program that names this provider holds it. The first lookup expands it one time, to about 230 KB, and the provider keeps it. TimeZones.version names the release.

Gotchas#

  • The release is the one of the Silk version that built the program. A zone rule that changed after that release is only in the files of the operating system.

Examples#

Read a zone on any target#

silk
import silk.mem.allocator { Allocator, OutOfMemoryError }
import silk.core.effect { Effect }
import silk.time.instant { Instant }
import silk.time.zoned { ZonedDateTime }
import silk.time.zones { TimeZones, ZoneLookupError }
import silk.time.zones_bundled { BundledTimeZones }

// The hour in Rome at `at`.
effect fn romeHour(at: Instant) -> u8 ! ZoneLookupError | OutOfMemoryError ? &mut TimeZones | &mut Allocator {
  let rome = run TimeZones.zone("Europe/Rome")
  return ZonedDateTime.make(at, &rome).time().hour()
}

effect fn failed(error: ZoneLookupError | OutOfMemoryError) -> u8 {
  return 255
}

pub effect fn main() -> i32 {
  let mut allocator = Allocator.systemAllocatorProvider()
  let mut zones = BundledTimeZones.make()
  let hour = run Effect.catchAll(romeHour(Instant.fromUnixSeconds(1795109782)), failed)
    |> Effect.provideMut<TimeZones>(&mut zones)
    |> Effect.provideMut<Allocator>(&mut allocator)
  if hour != 18 {
    return 1
  }
  return 0
}

Import as BundledTimeZones with import silk.time.zones_bundled { BundledTimeZones }.

Public declarations: 1.

BundledTimeZones#

silk
pub struct BundledTimeZones

The TimeZones provider with the time zone database inside the program.

Details#

BundledTimeZones.make does no work. The first operation expands the data, and the provider keeps it until it is dropped, so make one provider for the program and not one for each lookup.

Implementation BundledTimeZones#

silk
impl BundledTimeZones

Associated function make#

silk
pub fn make() -> BundledTimeZones

Returns a provider. It does not expand the data yet.

Method windowsZone#

silk
pub effect fn windowsZone(self: &mut Self, name: &[u8]) -> Option<Bytes>
    ! ZoneLookupError | OutOfMemoryError
    ? &mut Allocator

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 table does not list the name. Letter case does not matter.

Errors#

  • ZoneLookupError with the reason InvalidData if the data of the program is damaged.

  • OutOfMemoryError if the Allocator cannot supply the data or the name.

Implementation TimeZones for BundledTimeZones#

silk
impl TimeZones for BundledTimeZones

Operation zoneBytes#

silk
zoneBytes: BundledTimeZones.zoneBytes

Operation names#

silk
names: BundledTimeZones.names

Operation version#

silk
version: BundledTimeZones.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