I started investigating the handling of timezones and the TZ environment variable for #712.
Turns out documentation on this matter is a sad joke and I had to read glibc (tzset.c and tzfile.c) and musl source code. Here’s what I discovered:
- An empty
TZ indicates a UTC timezone
- When
TZ starts with :, the character is removed from the start of the string
- When
TZ is an absolute path (starts with /), it uses the file directly
- Otherwise it’s a relative path.
- glibc searches at the directory described by
TZDIR, or /usr/share/zoneinfo if it doesn’t exist
- musl searches in
/usr/share/zoneinfo/, then /share/zoneinfo/, then /etc/zoneinfo/.
Note 1: TZDIR is used by NixOS (it’s not documented anywhere but there are uses in their codebase…).
Note 2: At least one Linux distribution is using /etc/zoneinfo, apparently without TZDIR because it uses musl.
I started investigating the handling of timezones and the
TZenvironment variable for #712.Turns out documentation on this matter is a sad joke and I had to read glibc (tzset.c and tzfile.c) and musl source code. Here’s what I discovered:
TZindicates a UTC timezoneTZstarts with:, the character is removed from the start of the stringTZis an absolute path (starts with/), it uses the file directlyTZDIR, or/usr/share/zoneinfoif it doesn’t exist/usr/share/zoneinfo/, then/share/zoneinfo/, then/etc/zoneinfo/.Note 1:
TZDIRis used by NixOS (it’s not documented anywhere but there are uses in their codebase…).Note 2: At least one Linux distribution is using
/etc/zoneinfo, apparently withoutTZDIRbecause it uses musl.