Skip to content

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

@ariasuni

Description

@ariasuni

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions