Mercurial > public > mercurial-scm > hg-stable
diff mercurial/utils/dateutil.py @ 50748:faccec1edc2c stable
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...
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Tue, 27 Jun 2023 13:51:50 +0200 |
parents | 6000f5b25c9b |
children | 9d3721552b6c |
line wrap: on
line diff
--- a/mercurial/utils/dateutil.py Thu Jul 06 16:04:36 2023 +0200 +++ b/mercurial/utils/dateutil.py Tue Jun 27 13:51:50 2023 +0200 @@ -83,10 +83,14 @@ 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