datetime.utcfromtimestamp() and .utcnow() are deprecated
Closed this issue · 1 comments
ThomasWaldmann commented
src/moin/storage/middleware/indexing.py:177: DeprecationWarning:
datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in
a future version.
Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
doc[key] = datetime.datetime.utcfromtimestamp(doc[key])
Notable:
- it recommends using datetime.fromtimestamp instead of .utcfromtimestamp .
- it also recommends using timezone-aware datetime objects instead of naive datetime objects - but this is a bigger change and shall not be in the scope of this ticket! I filed #1676 for that topic.
https://docs.python.org/3/library/datetime.html#datetime.datetime.fromtimestamp
ThomasWaldmann commented
This is a 100% compatible replacement (we used that in borgbackup to avoid the deprecation warning):
def utcfromtimestamp(timestamp):
"""Returns a naive datetime instance representing the timestamp in the UTC timezone"""
return datetime.fromtimestamp(timestamp, timezone.utc).replace(tzinfo=None)