Skip to content

Commit

Permalink
Merge pull request #7715 from FelixSchwarz/py312-utcfromtimestamp
Browse files Browse the repository at this point in the history
replace "datetime.utcfromtimestamp" to avoid deprecation warnings with Python 3.12
  • Loading branch information
ThomasWaldmann authored Jul 6, 2023
2 parents e695683 + ae0b3d2 commit 29d73f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
8 changes: 3 additions & 5 deletions setup_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys
import textwrap
from collections import OrderedDict
from datetime import datetime
from datetime import datetime, timezone
import time

from setuptools import Command
Expand Down Expand Up @@ -470,10 +470,8 @@ def write_man_header(self, write, title, description):
self.write_heading(write, description, double_sided=True)
# man page metadata
write(":Author: The Borg Collective")
write(
":Date:",
datetime.utcfromtimestamp(int(os.environ.get("SOURCE_DATE_EPOCH", time.time()))).date().isoformat(),
)
source_date_epoch = int(os.environ.get("SOURCE_DATE_EPOCH", time.time()))
write(":Date:", datetime.fromtimestamp(source_date_epoch, timezone.utc).date().isoformat())
write(":Manual section: 1")
write(":Manual group: borg backup tool")
write()
Expand Down
17 changes: 11 additions & 6 deletions src/borg/testsuite/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,11 @@ def test_swidth_slice_mixed_characters():
assert swidth_slice(string, 6) == "나윤a"


def utcfromtimestamp(timestamp):
"""Returns a naive datetime instance representing the timestamp in the UTC timezone"""
return datetime.fromtimestamp(timestamp, timezone.utc).replace(tzinfo=None)


def test_safe_timestamps():
if SUPPORT_32BIT_PLATFORMS:
# ns fit into int64
Expand All @@ -1213,9 +1218,9 @@ def test_safe_timestamps():
# datetime won't fall over its y10k problem
beyond_y10k = 2**100
with pytest.raises(OverflowError):
datetime.utcfromtimestamp(beyond_y10k)
assert datetime.utcfromtimestamp(safe_s(beyond_y10k)) > datetime(2038, 1, 1)
assert datetime.utcfromtimestamp(safe_ns(beyond_y10k) / 1000000000) > datetime(2038, 1, 1)
utcfromtimestamp(beyond_y10k)
assert utcfromtimestamp(safe_s(beyond_y10k)) > datetime(2038, 1, 1)
assert utcfromtimestamp(safe_ns(beyond_y10k) / 1000000000) > datetime(2038, 1, 1)
else:
# ns fit into int64
assert safe_ns(2**64) <= 2**63 - 1
Expand All @@ -1226,9 +1231,9 @@ def test_safe_timestamps():
# datetime won't fall over its y10k problem
beyond_y10k = 2**100
with pytest.raises(OverflowError):
datetime.utcfromtimestamp(beyond_y10k)
assert datetime.utcfromtimestamp(safe_s(beyond_y10k)) > datetime(2262, 1, 1)
assert datetime.utcfromtimestamp(safe_ns(beyond_y10k) / 1000000000) > datetime(2262, 1, 1)
utcfromtimestamp(beyond_y10k)
assert utcfromtimestamp(safe_s(beyond_y10k)) > datetime(2262, 1, 1)
assert utcfromtimestamp(safe_ns(beyond_y10k) / 1000000000) > datetime(2262, 1, 1)


class TestPopenWithErrorHandling:
Expand Down

0 comments on commit 29d73f4

Please sign in to comment.