Skip to content

Commit fff3621

Browse files
author
Konstantin Baikov
committed
Fix a utcfromtimestamp warning
In python 3.12 the following DeprecationWarning datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC. This commit fixes it.
1 parent 4bd96a2 commit fff3621

File tree

2 files changed

+1
-2
lines changed

2 files changed

+1
-2
lines changed

src/time_machine/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def utcnow() -> dt.datetime:
351351
if not coordinates_stack:
352352
result: dt.datetime = _time_machine.original_utcnow()
353353
return result
354-
return dt.datetime.utcfromtimestamp(time())
354+
return dt.datetime.fromtimestamp(time(), dt.UTC)
355355

356356

357357
# time module

tox.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ commands =
1515
-W error::ResourceWarning \
1616
-W error::DeprecationWarning \
1717
-W error::PendingDeprecationWarning \
18-
-W ignore:datetime.datetime.utcfromtimestamp:DeprecationWarning \
1918
-W ignore:datetime.datetime.utcnow:DeprecationWarning \
2019
-m coverage run \
2120
-m pytest {posargs:tests}

0 commit comments

Comments
 (0)