Skip to content

Commit cc78e2a

Browse files
henryiiiAA-Turner
andauthored
Provide timezone information in datetime.fromtimestamp (#11468)
Python 3.12 has deprecated ``datetime.utcfromtimestamp``. Resolve the warning by working out ``tzdelta`` via explicit timezone calculations. Co-authored-by: Adam Turner <[email protected]>
1 parent 037b619 commit cc78e2a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

sphinx/builders/gettext.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from codecs import open
66
from collections import defaultdict
7-
from datetime import datetime, timedelta, tzinfo
7+
from datetime import datetime, timedelta, timezone, tzinfo
88
from os import getenv, path, walk
99
from time import time
1010
from typing import Any, Generator, Iterable
@@ -163,8 +163,10 @@ def write_doc(self, docname: str, doctree: nodes.document) -> None:
163163

164164
# determine tzoffset once to remain unaffected by DST change during build
165165
timestamp = time()
166-
tzdelta = datetime.fromtimestamp(timestamp) - \
167-
datetime.utcfromtimestamp(timestamp)
166+
local_time = datetime.fromtimestamp(timestamp)
167+
utc_time = datetime.fromtimestamp(timestamp, tz=timezone.utc)
168+
tzdelta = local_time - utc_time.replace(tzinfo=None)
169+
168170
# set timestamp from SOURCE_DATE_EPOCH if set
169171
# see https://reproducible-builds.org/specs/source-date-epoch/
170172
source_date_epoch = getenv('SOURCE_DATE_EPOCH')

0 commit comments

Comments
 (0)