Comment 1 for bug 1348797

Revision history for this message
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',