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

get_localzone returns 'local' on alpine linux docker container (Python:alpine) #44

Closed
ibigpapa opened this issue Jun 28, 2017 · 9 comments

Comments

@ibigpapa
Copy link

When i run tzlocal.get_localzone() it returns <StaticTzInfo 'local'>

Steps to recreate

  1. Get into shell of container: docker run --rm -it python:alpine /bin/sh
  2. Install tzlocal pip install tzlocal
  3. Launch python python
  4. Import and test
>>> tzlocal.get_localzone()
<StaticTzInfo 'local'>

output of /etc/localtime

cat /etc/localtime 
TZif2UTCTZif2UTC
UTC0

/usr/local/etc/localtime does not exist.

@regebro
Copy link
Owner

regebro commented Jun 28, 2017

This means none of the ways to figure out the time zone name worked. There may not be one on Alpine Linux, or it's sufficiently non-standard to not already be included.

Including a way would be possible if there is a reliable way to deduce the name in standard setups.

@ibigpapa
Copy link
Author

Heres a way to determine the name.

cat /etc/os-release 
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.4.6
PRETTY_NAME="Alpine Linux v3.4"
HOME_URL="http://alpinelinux.org"
BUG_REPORT_URL="http://bugs.alpinelinux.org"

@regebro
Copy link
Owner

regebro commented Jun 28, 2017

No, I mean the name of the time zone.

For example, Ubuntu writes it to /etc/timezone

@ibigpapa
Copy link
Author

You put me on the right path it appears that the Alpine docker container doesn't have TZ data in there. Following https://wiki.alpinelinux.org/wiki/Setting_the_timezone, makes it produce the proper TZ info when you call tzlocal.get_localzone()

@regebro
Copy link
Owner

regebro commented Jun 28, 2017

Super!

@benjaoming
Copy link

This is reported to be a problem too in Windows' Ubuntu Bash thing: learningequality/kolibri#2484

@regebro
Copy link
Owner

regebro commented Oct 20, 2017

Your system isn't configured in such a way that it's possible to figure out the timezone name. The timezone object returned is therefore using the name "local" for the time zone. This is not a bug, but a feature.

If you want a time zone name, configure your system properly.

@regebro regebro closed this as completed Oct 20, 2017
@benjaoming
Copy link

It's not my system, I'm reporting this on behalf of others having problems. The way I solved it wasn't to do much but raise pytz.UnknownTimeZoneError

@regebro
Copy link
Owner

regebro commented Oct 20, 2017

Yeah, if you need a timezone name, and tzlocal doesn't give that, that's a reasonable way to handle it.

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

No branches or pull requests

3 participants