Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

@satwell

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.

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