From fbddefc07a834e67d5710de7839a432e16895a89 Mon Sep 17 00:00:00 2001 From: Stuart Bishop Date: Mon, 21 Aug 2023 12:51:36 +1000 Subject: [PATCH] Hardcode epoch constant Rather than calculate it, hard code the Unix epoch as a timedelta for Python 2.7 compatibility. --- src/pytz/tzinfo.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pytz/tzinfo.py b/src/pytz/tzinfo.py index 6e20cb1..49b5c3f 100644 --- a/src/pytz/tzinfo.py +++ b/src/pytz/tzinfo.py @@ -1,6 +1,6 @@ '''Base classes and helpers for building zone specific tzinfo classes''' -from datetime import datetime, timedelta, timezone, tzinfo +from datetime import datetime, timedelta, tzinfo from bisect import bisect_right try: set @@ -24,7 +24,8 @@ def memorized_timedelta(seconds): _timedelta_cache[seconds] = delta return delta -_epoch = datetime.fromtimestamp(0, tz=timezone.utc).replace(tzinfo=None) + +_epoch = datetime(1970, 1, 1, 0, 0) # datetime.utcfromtimestamp(0) _datetime_cache = {0: _epoch} @@ -39,6 +40,7 @@ def memorized_datetime(seconds): _datetime_cache[seconds] = dt return dt + _ttinfo_cache = {} @@ -55,6 +57,7 @@ def memorized_ttinfo(*args): _ttinfo_cache[args] = ttinfo return ttinfo + _notime = memorized_timedelta(0)