From de8caf08a6aca2dccadf11ef25641c9e705fdf05 Mon Sep 17 00:00:00 2001 From: Manuel Ebert Date: Mon, 15 Jul 2013 13:37:30 +0200 Subject: [PATCH] Caches local timezone --- jrnl/util.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/jrnl/util.py b/jrnl/util.py index 973e7fd1..9ed4e1f6 100644 --- a/jrnl/util.py +++ b/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