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
d81f263e8c
commit
de8caf08a6
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
|
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
|
||||||
|
|
Loading…
Add table
Reference in a new issue