regebro / tzlocal

A Python module that tries to figure out what your local timezone is
MIT License
185 stars 58 forks source link

tzlocal/darwin.py relies on systemsetup which no longer works on OSX #42

Closed dexterp closed 6 years ago

dexterp commented 7 years ago

This is on macOS Sierra 10.12.3 (16D32)

% systemsetup -gettimezone You need administrator access to run this tool... exiting!

def _get_localzone():
    pipe = subprocess.Popen(
        "systemsetup -gettimezone",
        shell=True,
        stderr=subprocess.PIPE,
        stdout=subprocess.PIPE
    )
    tzname = pipe.stdout.read().replace(b'Time Zone: ', b'').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("zoneinfo/") + 9:]
    return pytz.timezone(tzname)
regebro commented 7 years ago

It should then fall back to the os.readlink way, so it shouldn't be a problem.

regebro commented 6 years ago

tzlocal will stop trying to use systemsetup in next release.