From 46c66afbea82f163e1281cef55295382ce0c3eda Mon Sep 17 00:00:00 2001 From: Konstantin Baikov <4488943+kbaikov@users.noreply.github.com> Date: Sat, 2 Mar 2024 00:02:25 +0100 Subject: [PATCH] Fix utcfromtimestamp() deprecation warning (#424) --- CHANGELOG.rst | 4 ++++ src/time_machine/__init__.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 1363a40..c6afce8 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,10 @@ Changelog ========= +* Fix ``utcfromtimestamp()`` warning on Python 3.12+. + + Thanks to Konstantin Baikov in `PR #424 `__. + * Avoid calling deprecated ``uuid._load_system_functions()`` on Python 3.9+. Thanks to Nikita Sobolev for the ping in `CPython Issue #113308 `__. diff --git a/src/time_machine/__init__.py b/src/time_machine/__init__.py index 4a6acd8..ee366f8 100644 --- a/src/time_machine/__init__.py +++ b/src/time_machine/__init__.py @@ -350,7 +350,7 @@ def utcnow() -> dt.datetime: if not coordinates_stack: result: dt.datetime = _time_machine.original_utcnow() return result - return dt.datetime.utcfromtimestamp(time()) + return dt.datetime.fromtimestamp(time(), dt.timezone.utc).replace(tzinfo=None) # time module