mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Caches local timezone
This commit is contained in:
parent
7511b17b6e
commit
ae733e6c66
1 changed files with 8 additions and 4 deletions
12
jrnl/util.py
12
jrnl/util.py
|
@ -4,6 +4,8 @@ import sys
|
|||
import os
|
||||
from tzlocal import get_localzone
|
||||
|
||||
__cached_tz = None
|
||||
|
||||
def py23_input(msg):
|
||||
if sys.version_info[0] == 3:
|
||||
try: return input(msg)
|
||||
|
@ -15,7 +17,9 @@ def get_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
|
||||
that prevents that right now: https://github.com/regebro/tzlocal/issues/6"""
|
||||
if "darwin" in sys.platform:
|
||||
return os.popen("systemsetup -gettimezone").read().replace("Time Zone: ", "").strip()
|
||||
else:
|
||||
return str(get_localzone())
|
||||
global __cached_tz
|
||||
if not __cached_tz and "darwin" in sys.platform:
|
||||
__cached_tz = os.popen("systemsetup -gettimezone").read().replace("Time Zone: ", "").strip()
|
||||
elif not __cached_tz:
|
||||
__cached_tz = str(get_localzone())
|
||||
return __cached_tz
|
||||
|
|
Loading…
Add table
Reference in a new issue