We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c9048bc commit b71a93fCopy full SHA for b71a93f
arctic/date/_mktz.py
@@ -3,6 +3,10 @@
3
import dateutil
4
import tzlocal
5
import six
6
+import weakref
7
+
8
9
+_TZ_CACHE = weakref.WeakValueDictionary()
10
11
12
class TimezoneError(Exception):
@@ -34,6 +38,11 @@ def mktz(zone=None):
34
38
if zone is None:
35
39
zone = tzlocal.get_localzone().zone
36
40
zone = six.u(zone)
41
42
+ cached = _TZ_CACHE.get(zone)
43
+ if cached is not None:
44
+ return cached
45
37
46
tz = dateutil.tz.gettz(zone)
47
if not tz:
48
raise TimezoneError('Timezone "%s" can not be read' % (zone))
@@ -44,4 +53,5 @@ def mktz(zone=None):
53
if zone.startswith(p):
54
tz.zone = zone[len(p) + 1:]
55
break
56
+ _TZ_CACHE[zone] = tz
57
return tz
0 commit comments