Merge pull request #94 from maebert/timezone-fix

Fixes timezone detection for non-admin accounts on OS X
This commit is contained in:
Manuel Ebert 2013-09-16 11:10:02 -07:00
commit 7f4824f97b
3 changed files with 13 additions and 1 deletions

View file

@ -3,6 +3,10 @@ Changelog
#### 1.5.5 #### 1.5.5
* [Fixed] Fixed a bug where on OS X, the timezone could only be accessed on administrator accounts.
#### 1.5.5
* [Fixed] Detects DayOne journals stored in `~/Library/Mobile Data` as well. * [Fixed] Detects DayOne journals stored in `~/Library/Mobile Data` as well.
#### 1.5.4 #### 1.5.4

View file

@ -7,7 +7,7 @@ jrnl is a simple journal application for your command line.
""" """
__title__ = 'jrnl' __title__ = 'jrnl'
__version__ = '1.5.5' __version__ = '1.5.6'
__author__ = 'Manuel Ebert' __author__ = 'Manuel Ebert'
__license__ = 'MIT License' __license__ = 'MIT License'
__copyright__ = 'Copyright 2013 Manuel Ebert' __copyright__ = 'Copyright 2013 Manuel Ebert'

View file

@ -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()
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:]
elif not __cached_tz: elif not __cached_tz:
__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