# HG changeset patch # User Mads Kiilerich # Date 2023-06-27 11:51:50 # Node ID faccec1edc2c44ed13d2c1af0ec8fe34c4dbd2b4 # Parent fa2eca7423f3f2c9aeb1a234d9c0f79ccdba80c4 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... diff --git a/hgext/convert/common.py b/hgext/convert/common.py --- a/hgext/convert/common.py +++ b/hgext/convert/common.py @@ -567,8 +567,10 @@ class mapfile(dict): def makedatetimestamp(t): """Like dateutil.makedate() but for time t instead of current time""" - delta = datetime.datetime.utcfromtimestamp( + tz = round( t - ) - datetime.datetime.fromtimestamp(t) - tz = delta.days * 86400 + delta.seconds + - datetime.datetime.fromtimestamp(t) + .replace(tzinfo=datetime.timezone.utc) + .timestamp() + ) return t, tz diff --git a/mercurial/utils/dateutil.py b/mercurial/utils/dateutil.py --- a/mercurial/utils/dateutil.py +++ b/mercurial/utils/dateutil.py @@ -83,10 +83,14 @@ def makedate(timestamp=None): raise error.InputError( _(b"negative timestamp: %d") % timestamp, hint=hint ) - delta = datetime.datetime.utcfromtimestamp( + tz = round( timestamp - ) - datetime.datetime.fromtimestamp(timestamp) - tz = delta.days * 86400 + delta.seconds + - datetime.datetime.fromtimestamp( + timestamp, + ) + .replace(tzinfo=datetime.timezone.utc) + .timestamp() + ) return timestamp, tz