From caba423e3c0a4df18f917a8367fc31c8345af8e8 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 11 Jun 2025 20:18:04 +0200 Subject: [PATCH] Clean up datetime.fromtimestamp timezone handling Replace `datetime.datetime.utcfromtimestamp`, which is deprecated since Python 3.12, by `datetime.datetime.fromtimestamp` on `datetime.timezone.utc`, which has existed since Python 3.2. Also fix file timestamps, which were in the local time zone rather than UTC. This had no practical consequence since the script only uses those timestamps to compare with other file timestamps. (In particular, all uncommitted files are ordered after all committed files, so the script never compares a formerly-UTC timestamp of a committed file to a formerly-local timestamp of an uncommitted file.) Signed-off-by: Gilles Peskine --- scripts/assemble_changelog.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/assemble_changelog.py b/scripts/assemble_changelog.py index 07e6fc58ac..99c97a9029 100755 --- a/scripts/assemble_changelog.py +++ b/scripts/assemble_changelog.py @@ -350,13 +350,13 @@ def commit_timestamp(commit_id): text = subprocess.check_output(['git', 'show', '-s', '--format=%ct', commit_id]) - return datetime.datetime.utcfromtimestamp(int(text)) + return datetime.datetime.fromtimestamp(int(text), datetime.timezone.utc) @staticmethod def file_timestamp(filename): """Return the modification timestamp of the given file.""" mtime = os.stat(filename).st_mtime - return datetime.datetime.fromtimestamp(mtime) + return datetime.datetime.fromtimestamp(mtime, datetime.timezone.utc) def __init__(self, filename): """Determine position of the file in the changelog entry order.