Skip to content

Commit 2e11deb

Browse files
committed
Avoid zoneinfo. LP: #2103478
1 parent 03a680e commit 2e11deb

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

breezy/osutils.py

+7-15
Original file line numberDiff line numberDiff line change
@@ -759,26 +759,18 @@ def compare_files(a, b):
759759

760760
def local_time_offset(t=None):
761761
"""Return offset of local zone from GMT, either at present or at time t."""
762-
from datetime import datetime
763-
764762
if t is None:
765763
t = time.time()
766-
try:
767-
from datetime import UTC
768-
except ImportError:
769-
offset = datetime.fromtimestamp(t) - datetime.utcfromtimestamp(t)
770-
else:
771-
from zoneinfo import ZoneInfo
772764

773-
now = datetime.now()
774-
tzinfo = now.astimezone().tzinfo
775-
if tzinfo is None:
776-
raise errors.BzrError("No timezone information available")
777-
zoneinfo = ZoneInfo(tzinfo.tzname(now))
765+
local_time = time.localtime(t)
766+
utc_time = time.gmtime(t)
767+
768+
local_seconds = time.mktime(local_time)
769+
utc_seconds = time.mktime(utc_time)
778770

779-
offset = datetime.fromtimestamp(t, zoneinfo) - datetime.fromtimestamp(t, UTC)
771+
offset = int(local_seconds - utc_seconds)
780772

781-
return offset.days * 86400 + offset.seconds
773+
return offset
782774

783775

784776
weekdays = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]

0 commit comments

Comments
 (0)