Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle TZ environment variable correctly and add support for TZDIR #856

Closed
ariasuni opened this issue Apr 25, 2021 · 5 comments
Closed

Handle TZ environment variable correctly and add support for TZDIR #856

ariasuni opened this issue Apr 25, 2021 · 5 comments

Comments

@ariasuni
Copy link
Collaborator

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.

@mx-psi
Copy link

mx-psi commented Apr 30, 2022

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

@ariasuni
Copy link
Collaborator Author

ariasuni commented May 2, 2022

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.

@pitdicker
Copy link

Please open an issue against chrono if there is something we can do to help on our side.

@ariasuni
Copy link
Collaborator Author

ariasuni commented Sep 8, 2023

Since exa is unmaintained (see #1243), I’m working to merge my «use-chrono» PR in the active fork eza, see eza-community/eza#227.

@ariasuni
Copy link
Collaborator Author

It’s been merged in eza!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants