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

Remove determining time zone via systemsetup on macOS #914

Merged
merged 1 commit into from Oct 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 0 additions & 24 deletions babel/localtime/_unix.py
@@ -1,10 +1,6 @@
import os
import re
import sys
import pytz
import subprocess

_systemconfig_tz = re.compile(r'^Time Zone: (.*)$', re.MULTILINE)


def _tz_from_env(tzenv):
Expand Down Expand Up @@ -57,26 +53,6 @@ def _get_localzone(_root='/'):
except pytz.UnknownTimeZoneError:
pass

# If we are on OS X now we are pretty sure that the rest of the
# code will fail and just fall through until it hits the reading
# of /etc/localtime and using it without name. At this point we
# can invoke systemconfig which internally invokes ICU. ICU itself
# does the same thing we do (readlink + compare file contents) but
# since it knows where the zone files are that should be a bit
# better than reimplementing the logic here.
if sys.platform == 'darwin':
c = subprocess.Popen(['systemsetup', '-gettimezone'],
stdout=subprocess.PIPE)
sys_result = c.communicate()[0]
c.wait()
tz_match = _systemconfig_tz.search(sys_result)
if tz_match is not None:
zone_name = tz_match.group(1)
try:
return pytz.timezone(zone_name)
except pytz.UnknownTimeZoneError:
pass

# Now look for distribution specific configuration files
# that contain the timezone name.
tzpath = os.path.join(_root, 'etc/timezone')
Expand Down