Skip to main content

Crate local_time

Crate local_time 

Source
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, the TZ format of POSIX tzset. 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.
TimeZone
A parsed POSIX TZ string.

Enums§

ParseError
Why a POSIX TZ string was rejected.
SettingError
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 TZ variable, parsed. UTC when the task has no TZ or when it does not parse.
initialize
Load the stored setting and publish its TZ string as TZ via [task::Manager::set_system_environment_variable] (in the root task and in every task whose TZ matches the root task’s previous value, which is every task without TZ when 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; initialize reports 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 initialize loaded or that set stored last, or UTC before initialize. 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) in zone, for example 2026-03-29 03:00:00 CEST (UTC+02:00). Settings and the shell share it, so it takes a dyn writer and is linked once.
write_offset
Write a UTC offset in seconds as +HH:MM, or +HH:MM:SS when the seconds are not zero. For example, 3600 is +01:00 and -12600 is -03:30.