silk.platform.native.time_zone.
Direct reads of the time zone files and settings of a Unix system, for the native zone providers.
When to use#
silk.time.zones_native uses NativeTimeZone. Application code uses those providers
through the TimeZones and LocalZone effects, so a test can replace them.
Details#
Zone files are looked for in the directory that the variable TZDIR names, then in
/usr/share/zoneinfo, /var/db/timezone/zoneinfo, /usr/lib/zoneinfo,
/usr/share/lib/zoneinfo, and /etc/zoneinfo. The first directory that has the file wins.
The local zone is the value of the variable TZ, or the zone that the link /etc/localtime
points to, or the first line of /etc/timezone.
Gotchas#
The names are not checked here. The caller must check a name with
TimeZones.isValidNamebefore it reads a file, so that a name cannot leave the zone directory.This module exists on Darwin x86_64 or aarch64 and on GNU Linux x86_64 or aarch64.
Import as NativeTimeZone with import silk.platform.native.time_zone { NativeTimeZone }.
Public declarations: 1.
NativeTimeZone#
pub struct NativeTimeZoneThe time zone files and settings of the system.
Implementation NativeTimeZone#
impl NativeTimeZoneAssociated function readZoneFile#
pub effect fn readZoneFile(name: &[u8]) -> Option<Bytes> ! OutOfMemoryError ? &mut AllocatorReturns the contents of the file name of the zone directory, such as Europe/Rome or
tzdata.zi, or None if no zone directory has a readable file with that name.
Gotchas#
name is joined to the directory as it is. Check it with TimeZones.isValidName first.
Errors#
OutOfMemoryErrorif theAllocatorcannot supply the contents.
Associated function localName#
pub effect fn localName() -> Option<Bytes> ! OutOfMemoryError ? &mut AllocatorReturns the name of the zone that the system is set to, or None if the system does not
say.
Details#
A set TZ variable wins: a leading : is removed, a path into a zone directory gives the
part after zoneinfo/, and an empty value means UTC. Without TZ, the answer is the part
after zoneinfo/ of the target of the link /etc/localtime, and then the first line of
/etc/timezone. The name is not checked against the zone files, and a TZ value can be a
POSIX rule and not a name.
Errors#
OutOfMemoryErrorif theAllocatorcannot supply the name.
Category: Native platform.
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, x86_64-unknown-linux-gnu.