Skip to content

Commit

Permalink
Avoid deprecated utcfromtimestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Feb 1, 2024
1 parent ac3ab8b commit d1647e7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions breezy/doc_generate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def get_autodoc_datetime():
:return: A `datetime` object
"""
try:
return datetime.datetime.utcfromtimestamp(
int(os.environ['SOURCE_DATE_EPOCH']))
return datetime.datetime.fromtimestamp(
int(os.environ['SOURCE_DATE_EPOCH']),
datetime.UTC)
except (KeyError, ValueError):
return datetime.datetime.utcnow()
5 changes: 3 additions & 2 deletions breezy/osutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,10 +736,11 @@ def compare_files(a, b):

def local_time_offset(t=None):
"""Return offset of local zone from GMT, either at present or at time t."""
from datetime import datetime
from datetime import datetime, UTC
from tzlocal import get_localzone
if t is None:
t = time.time()
offset = datetime.fromtimestamp(t) - datetime.utcfromtimestamp(t)
offset = datetime.fromtimestamp(t, get_localzone()) - datetime.fromtimestamp(t, UTC)
return offset.days * 86400 + offset.seconds


Expand Down
2 changes: 1 addition & 1 deletion breezy/plugins/weave_fmt/xml4.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def _unpack_revision(self, elt):

pelts = elt.find('parents')

if pelts:
if pelts is not None:
for p in pelts:
rev.parent_ids.append(p.get('revision_id'))
rev.parent_sha1s.append(p.get('revision_sha1'))
Expand Down
4 changes: 2 additions & 2 deletions breezy/tests/test_selftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,11 +809,11 @@ def test_uses_time_from_testtools(self):

class TimeAddedVerboseTestResult(tests.VerboseTestResult):
def startTest(self, test):
self.time(datetime.datetime.utcfromtimestamp(1.145))
self.time(datetime.datetime.fromtimestamp(1.145, datetime.UTC))
super().startTest(test)

def addSuccess(self, test):
self.time(datetime.datetime.utcfromtimestamp(51.147))
self.time(datetime.datetime.fromtimestamp(51.147, datetime.UTC))
super().addSuccess(test)

def report_tests_starting(self): pass
Expand Down

0 comments on commit d1647e7

Please sign in to comment.