Skip to content

Commit 46c66af

Browse files
authored
Fix utcfromtimestamp() deprecation warning (#424)
1 parent 2eda5ad commit 46c66af

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
Changelog
33
=========
44

5+
* Fix ``utcfromtimestamp()`` warning on Python 3.12+.
6+
7+
Thanks to Konstantin Baikov in `PR #424 <https://github.com/adamchainz/time-machine/pull/424>`__.
8+
59
* Avoid calling deprecated ``uuid._load_system_functions()`` on Python 3.9+.
610

711
Thanks to Nikita Sobolev for the ping in `CPython Issue #113308 <https://github.com/python/cpython/issues/113308>`__.

src/time_machine/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def utcnow() -> dt.datetime:
350350
if not coordinates_stack:
351351
result: dt.datetime = _time_machine.original_utcnow()
352352
return result
353-
return dt.datetime.utcfromtimestamp(time())
353+
return dt.datetime.fromtimestamp(time(), dt.timezone.utc).replace(tzinfo=None)
354354

355355

356356
# time module

0 commit comments

Comments
 (0)