Expand description
The system time zone setting of Xila.
Civil time stays outside the kernel clock: the time subsystem keeps UTC
and monotonic time only (xila-project/core#463). This crate stores the time
zone that the user chose, loads it at start-up and publishes it to every
task as the POSIX TZ environment variable. Programs convert UTC to local
time with the xila-time-zone crate.
§Stored setting
CONFIGURATION_PATH (/configuration/system/time_zone.json) holds one
JSON object:
{ "name": "Europe/Paris", "time_zone": "CET-1CEST,M3.5.0,M10.5.0/3" }time_zone(required) is the POSIX TZ string, theTZformat of POSIXtzset. It is the only value that Core reads and publishes, so Core needs no IANA zone table.name(optional) is the IANA zone name that the user chose, for display only. It is absent when the user entered a custom TZ string. A program with a newer zone table can resolve the name again. An invalid name is dropped and the TZ string still applies.
Only root may have written the file: it belongs to root, others cannot
write it, and its group can only if it is root’s group, as for the other
files of /configuration/system. Everyone can read it. set replaces it
atomically (a temporary file created with mode 0644, then a rename; a
temporary file left by a failed write is truncated by the next one). A
missing, unreadable or invalid file gives UTC (UTC0) and one warning at
start-up, from initialize; load logs nothing. It never blocks the
start-up.
§Publication
initialize runs once at start-up, before the shell, and publishes the
stored TZ string via [task::Manager::set_system_environment_variable]: in
the root task and in every task whose current TZ matches the root task’s
previous value (every task without TZ when called once at start-up).
Every task inherits the environment of its parent, so native executables
and WebAssembly guests (through WASI environ_get) see TZ from their
start.
set writes the file and then gives TZ the new value in the root task
and in every task whose TZ is still the previous system value
([task::Manager::set_system_environment_variable]); a task that set a TZ
of its own keeps it, unless it set the system value itself: such a task
cannot be told apart from one that inherited the value, so it follows the
change. Calls of set are serialised, so the file and TZ always hold
the same setting. Tasks started after the change get the new value at
once. A native program that reads TZ again, for example through
current on each display update, follows the change. A WebAssembly guest
copies its environment when it starts, so a running guest keeps the old
value until it is restarted.
§Sizes
On 32-bit targets, Setting is 24 bytes (two heap strings, the name with
the niche of Option) and SettingError is 1 byte.
Re-exports§
pub use time_zone;
Structs§
- Setting
- A valid time zone setting: an optional zone name and a POSIX TZ string.
- Time
Zone - A parsed POSIX TZ string.
Enums§
- Parse
Error - Why a POSIX TZ string was rejected.
- Setting
Error - Why a setting is rejected.
Constants§
- CONFIGURATION_
PATH - The file that holds the setting.
- DEFAULT_
TIME_ ZONE - The TZ string used when no valid setting is stored: UTC.
- ENVIRONMENT_
VARIABLE - The environment variable that holds the POSIX TZ string of the system time zone.
- MAXIMUM_
CONFIGURATION_ SIZE - The largest configuration file read, in bytes.
- MAXIMUM_
NAME_ LENGTH - The longest zone name accepted, in bytes. The longest IANA name of tzdata
2026f has 32 bytes (
America/Argentina/ComodRivadavia). - MAXIMUM_
TIME_ ZONE_ LENGTH - The longest TZ string accepted, in bytes. The longest TZ string of tzdata
2026f has 50 bytes (
Pacific/Chatham).
Functions§
- current
- The time zone of a task: its
TZvariable, parsed. UTC when the task has noTZor when it does not parse. - initialize
- Load the stored setting and publish its TZ string as
TZvia [task::Manager::set_system_environment_variable] (in the root task and in every task whoseTZmatches the root task’s previous value, which is every task withoutTZwhen called once at start-up). Call it once at start-up, after the file systems are mounted and before the shell or the startup application starts. It returns the setting in use, UTC when the stored one is missing or invalid. - is_
administrator - Whether a user may change the system time zone: root, or a member of the administrator group.
- load
- Read the stored setting, or UTC when it is missing or invalid. It logs
nothing;
initializereports at start-up why UTC is used. - read
- Read the stored setting, without a fallback.
- set
- Store a new setting and publish it.
- stored
- The setting in use: the one that
initializeloaded or thatsetstored last, or UTC beforeinitialize. It does not read the file. - utc
- UTC as a parsed time zone.
- validate_
time_ zone - Check a POSIX TZ string as a setting: its length and its syntax.
- write_
local_ time - Write the local time of
utc(seconds since the Unix epoch) inzone, for example2026-03-29 03:00:00 CEST (UTC+02:00). Settings and the shell share it, so it takes adynwriter and is linked once. - write_
offset - Write a UTC offset in seconds as
+HH:MM, or+HH:MM:SSwhen the seconds are not zero. For example,3600is+01:00and-12600is-03:30.