Caches local timezone

This commit is contained in:
Manuel Ebert 2013-07-15 13:37:30 +02:00
parent d81f263e8c
commit de8caf08a6

View file

@ -4,6 +4,8 @@ import sys
import os import os
from tzlocal import get_localzone from tzlocal import get_localzone
__cached_tz = None
def py23_input(msg): def py23_input(msg):
if sys.version_info[0] == 3: if sys.version_info[0] == 3:
try: return input(msg) try: return input(msg)
@ -15,7 +17,9 @@ def get_local_timezone():
"""Returns the Olson identifier of the local timezone. """Returns the Olson identifier of the local timezone.
In a happy world, tzlocal.get_localzone would do this, but there's a bug on OS X In a happy world, tzlocal.get_localzone would do this, but there's a bug on OS X
that prevents that right now: https://github.com/regebro/tzlocal/issues/6""" that prevents that right now: https://github.com/regebro/tzlocal/issues/6"""
if "darwin" in sys.platform: global __cached_tz
return os.popen("systemsetup -gettimezone").read().replace("Time Zone: ", "").strip() if not __cached_tz and "darwin" in sys.platform:
else: __cached_tz = os.popen("systemsetup -gettimezone").read().replace("Time Zone: ", "").strip()
return str(get_localzone()) elif not __cached_tz:
__cached_tz = str(get_localzone())
return __cached_tz