Skip to content
Snippets Groups Projects
Commit faccec1edc2c authored by kiilerix's avatar kiilerix
Browse files

utils: stop using datetime.utcfromtimestamp() deprecated in Python 3.12

Python3.12 made tests fail with warnings:
  DeprecationWarning: datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.fromtimestamp(timestamp, datetime.UTC).

Computing the diff while in timestamp seconds seems to preserve to the original
intent from ae04af1ce78d.

It would be nice to have some doctest coverage of this, with the problematic
corner cases that has popped up over time...
parent fa2eca7423f3
No related branches found
No related tags found
2 merge requests!647branching: merge stable into default,!627A bunch of 3.12 compat stuff
......@@ -567,5 +567,5 @@
def makedatetimestamp(t):
"""Like dateutil.makedate() but for time t instead of current time"""
delta = datetime.datetime.utcfromtimestamp(
tz = round(
t
......@@ -571,4 +571,6 @@
t
) - datetime.datetime.fromtimestamp(t)
tz = delta.days * 86400 + delta.seconds
- datetime.datetime.fromtimestamp(t)
.replace(tzinfo=datetime.timezone.utc)
.timestamp()
)
return t, tz
......@@ -83,5 +83,5 @@
raise error.InputError(
_(b"negative timestamp: %d") % timestamp, hint=hint
)
delta = datetime.datetime.utcfromtimestamp(
tz = round(
timestamp
......@@ -87,6 +87,10 @@
timestamp
) - datetime.datetime.fromtimestamp(timestamp)
tz = delta.days * 86400 + delta.seconds
- datetime.datetime.fromtimestamp(
timestamp,
)
.replace(tzinfo=datetime.timezone.utc)
.timestamp()
)
return timestamp, tz
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment