Skip to content

Pendulum shouldn't rely on Linux distro-specific timezone configuration #837

Open

Description

@satwell
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have searched the documentation and believe that my question is not covered.

Issue

I see in pendulum.tz.local_timezone that Pendulum tries to get the local timezone from some distro-specific files such as /etc/timezone and /etc/sysconfig/clock. It only falls back to /etc/localtime if these files don't exist. But libc only uses /etc/localtime to get the system default local timezone. (glibc source is hard to follow, but this is pretty clear in do_tzset() in musl libc.)

This can lead to weird behavior where most apps (e.g., the date command) think the system uses one timezone, but Pendulum thinks it uses a different one. For example, one way that people sometimes override the timezone in Docker containers is to bind mount /etc/localtime from the host system into the container. Which can result in a mismatch between /etc/localtime and /etc/timezone but works fine for almost everything because libc only uses /etc/localtime.

See also https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=822733 where Debian is working on getting rid of /etc/timezone.

It seems like it would be best to remove handling of the distro-specific configs, and only use os.environ['TZ'] and /etc/localtime on Linux.

Activity

  1. Rafnel commented on Sep 13, 2024

    @Rafnel

    +1 on this issue. I think usage of /etc/timezone should be removed entirely, although I don't have enough knowledge of the history of Linux or potential compatibility issues to be confident enough to remove it. I'm on Ubuntu, and if you use the timedatectl utility to change the local timezone, it updates /etc/localtime but not /etc/timezone. This created a lot of confusion until I dove into the Pendulum source code and found that it prioritizes the /etc/timezone file over /etc/localtime. Updating /etc/timezone manually works, but seems like a poor solution.

    If nothing else, I think it would be pretty harmless to move this code block: https://github.com/sdispater/pendulum/blob/3e3fec6a5b66759078c5ae39c736ca95b78adbef/src/pendulum/tz/local_timezone.py#L234-L242 up to the top of the function (above https://github.com/sdispater/pendulum/blob/3e3fec6a5b66759078c5ae39c736ca95b78adbef/src/pendulum/tz/local_timezone.py#L164) so that /etc/localtime is properly prioritized over the old/deprecated /etc/timezone. StackOverflow seems to agree that /etc/localtime is the proper place in most Linux environments to derive the system timezone: https://unix.stackexchange.com/questions/451709/timedatectl-set-timezone-doesnt-update-etc-timezone/451714#451714

  2. added this to the Pendulum 3.2 milestone on Apr 23, 2025
  3. jacobg commented on Oct 15, 2026

    @jacobg

    any update on this?

    gcp cloud run's python 3.14 runtime container has /etc/timezone configuration set to /UTC which causes pendulum to throw errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions