mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Fixes #93
This commit is contained in:
parent
d4e7ae9c3e
commit
830cfb37d1
1 changed files with 9 additions and 1 deletions
10
jrnl/util.py
10
jrnl/util.py
|
@ -4,6 +4,7 @@ import sys
|
||||||
import os
|
import os
|
||||||
from tzlocal import get_localzone
|
from tzlocal import get_localzone
|
||||||
import getpass as gp
|
import getpass as gp
|
||||||
|
import pytz
|
||||||
|
|
||||||
PY3 = sys.version_info[0] == 3
|
PY3 = sys.version_info[0] == 3
|
||||||
PY2 = sys.version_info[0] == 2
|
PY2 = sys.version_info[0] == 2
|
||||||
|
@ -41,6 +42,13 @@ def get_local_timezone():
|
||||||
global __cached_tz
|
global __cached_tz
|
||||||
if not __cached_tz and "darwin" in sys.platform:
|
if not __cached_tz and "darwin" in sys.platform:
|
||||||
__cached_tz = os.popen("systemsetup -gettimezone").read().replace("Time Zone: ", "").strip()
|
__cached_tz = os.popen("systemsetup -gettimezone").read().replace("Time Zone: ", "").strip()
|
||||||
elif not __cached_tz:
|
if not __cached_tz or __cached_tz not in pytz.all_timezones_set:
|
||||||
|
link = os.readlink("/etc/localtime")
|
||||||
|
# This is something like /usr/share/zoneinfo/America/Los_Angeles.
|
||||||
|
# Find second / from right and take the substring
|
||||||
|
__cached_tz = link[link.rfind('/', 0, link.rfind('/'))+1:]
|
||||||
|
if not __cached_tz or __cached_tz not in pytz.all_timezones_set:
|
||||||
__cached_tz = str(get_localzone())
|
__cached_tz = str(get_localzone())
|
||||||
|
if not __cached_tz or __cached_tz not in pytz.all_timezones_set:
|
||||||
|
__cached_tz = "UTC"
|
||||||
return __cached_tz
|
return __cached_tz
|
||||||
|
|
Loading…
Add table
Reference in a new issue