Skip to content

Commit

Permalink
Fix a utcfromtimestamp warning
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Konstantin Baikov committed Feb 26, 2024
1 parent 4bd96a2 commit fff3621
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 2 deletions.
2 changes: 1 addition & 1 deletion src/time_machine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,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.UTC)


# time module
Expand Down
1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ commands =
-W error::ResourceWarning \
-W error::DeprecationWarning \
-W error::PendingDeprecationWarning \
-W ignore:datetime.datetime.utcfromtimestamp:DeprecationWarning \
-W ignore:datetime.datetime.utcnow:DeprecationWarning \
-m coverage run \
-m pytest {posargs:tests}
Expand Down

0 comments on commit fff3621

Please sign in to comment.