issue on MacOS X 10.9.3 with buenos aires
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
pytz |
Invalid
|
Undecided
|
Unassigned |
Bug Description
Trying to get local time zone when my Mac OS X time zone is set to Argentina/Buenos Aires fails on me.
python
Python 2.7.6 (v2.7.6:
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from tzlocal import get_localzone
>>> get_localzone()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "tzlocal/
_cache_tz = _get_localzone()
File "tzlocal/
return pytz.timezone(
File "/Users/
pytz.exceptions
description: | updated |
ok I analyzed the issue
tzname = os.popen( "systemsetup -gettimezone" ).read( ).replace( "Time Zone: ", "").strip() timezones_ set: zoneinfo/ America/ Los_Angeles. "/etc/localtime ") rfind(' /', 0, link.rfind( '/'))+1: ] tzname)
if not tzname or tzname not in pytz.all_
# link will be something like /usr/share/
link = os.readlink(
tzname = link[link.
return pytz.timezone(
The above code will run like this
tzname = os.popen( "systemsetup -gettimezone" ).read( ).replace( "Time Zone: ", "").strip()
This line won't work because you need admin access to get that tool: This you will get back:
You need administrator access to run this tool... exiting!
Then link = os.readlink( "/etc/localtime ")
Will give back
/usr/share/ zoneinfo/ America/ Argentina/ Buenos_ Aires
link[link. rfind(' /', 0, link.rfind( '/'))+1: ]
and above code will only return Argentina/ Buenos_ Aires
Looking at above code there are many pytz.all_ timezones_ set where this code will actually fail:
'America/ Indiana/ Indianapolis' , 'America/ Indiana/ Knox', 'America/ Indiana/ Marengo' , 'America/ Indiana/ Petersburg' , 'America/ Indiana/ Tell_City' , 'America/ Indiana/ Vevay', 'America/ Indiana/ Vincennes' , 'America/ Indiana/ Winamac'
'America/ Argentina/ Buenos_ Aires', 'America/ Argentina/ Catamarca' , 'America/ Argentina/ ComodRivadavia' , 'America/ Argentina/ Cordoba' , 'America/ Argentina/ Jujuy', 'America/ Argentina/ La_Rioja' , 'America/ Argentina/ Mendoza' , 'America/ Argentina/ Rio_Gallegos' , 'America/ Argentina/ Salta', 'America/ Argentina/ San_Juan' , 'America/ Argentina/ San_Luis' , 'America/ Argentina/ Tucuman' , 'America/ Argentina/ Ushuaia' ,