exa
exa copied to clipboard
Handle `TZ` environment variable correctly and add support for `TZDIR`
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/
.
- glibc searches at the directory described by
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.
In case it's useful, it looks like exa doesn't handle TZ
correctly on Fedora 35. It falls under the case "When TZ is an absolute path (starts with /)" + "When TZ starts with :, the character is removed from the start of the string" since I have:
❯ echo "TZ: '$TZ', TZDIR: '$TZDIR'"
TZ: ':/etc/localtime', TZDIR: ''
Running ls -la ~
outputs "Unable to determine time zone: No such file or directory (os error 2)", while running TZ="Europe/Paris" ls -la ~
does not have any error in the output since:
❯ file /etc/localtime
/etc/localtime: symbolic link to ../usr/share/zoneinfo/Europe/Paris
I already knew all that, but mostly the chrono
crate will handle that stuff for me (by relying on the libc of the system) instead of trying to emulate the actual behavior… I just need some time to rereview my code and finally merge it.
Please open an issue against chrono if there is something we can do to help on our side.
Since exa is unmaintained (see https://github.com/ogham/exa/issues/1243), I’m working to merge my «use-chrono» PR in the active fork eza, see https://github.com/eza-community/eza/pull/227.
It’s been merged in eza!