issue on MacOS X 10.9.3 with buenos aires

Bug #1348797 reported by Marc Van Olmen on 2014-07-25
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
pytz
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:3a1db0d2747e, Nov 10 2013, 00:42:54)
[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/darwin.py", line 20, in get_localzone
    _cache_tz = _get_localzone()
  File "tzlocal/darwin.py", line 14, in _get_localzone
    return pytz.timezone(tzname)
  File "/Users/marcvano/dev/Acclivity/checkout4_env/lib/python2.7/site-packages/pytz-2014.4-py2.7.egg/pytz/__init__.py", line 180, in timezone
pytz.exceptions.UnknownTimeZoneError: 'Argentina/Buenos_Aires'

description: updated
Marc Van Olmen (marcvanolmen) wrote :

ok I analyzed the issue

    tzname = os.popen("systemsetup -gettimezone").read().replace("Time Zone: ", "").strip()
    if not tzname or tzname not in pytz.all_timezones_set:
        # link will be something like /usr/share/zoneinfo/America/Los_Angeles.
        link = os.readlink("/etc/localtime")
        tzname = link[link.rfind('/', 0, link.rfind('/'))+1:]
    return pytz.timezone(tzname)

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',

Marc Van Olmen (marcvanolmen) wrote :

Also these ones

'America/North_Dakota/Beulah', 'America/North_Dakota/Center', 'America/North_Dakota/New_Salem'

Marc Van Olmen (marcvanolmen) wrote :

my current workaround it the following:
to replace

link[link.rfind('/', 0, link.rfind('/'))+1:]

with

link[link.rfind("zoneinfo/") + 9:]

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers