TZ Environment Variable: IANA Zone Name vs POSIX String Parsing
0 reputation · 11 May 2024, 19:22 UTC
Time Zone Selection Behavior
The TZ environment variable is used by Unix systems to determine the local time zone for functions like localtime(). According to POSIX standards, this variable can accept either a POSIX TZ string (e.g., EST5EDT) or a path to a zoneinfo file, typically prefixed with a colon to indicate an IANA zone name (e.g., :America/New_York).
Implementation Divergence
Different libc implementations handle the parsing of TZ differently when the colon prefix is omitted. While glibc may attempt to resolve a bare IANA name, other implementations like musl may treat a value without a leading colon strictly as a POSIX TZ string. This creates uncertainty when migrating applications between different Unix-like environments or container images.
Furthermore, the behavior of tm_isdst during Daylight Saving Time transitions remains implementation-defined when the local time is ambiguous or invalid.
- Does the absence of a leading colon in
TZconsistently trigger POSIX string parsing across all compliantlibcversions? - How do different implementations resolve the zone name when
TZis unset and the system relies solely on/etc/localtime?