Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datetime.utcfromtimestamp() and .utcnow() are deprecated #1675

Closed
ThomasWaldmann opened this issue Apr 5, 2024 · 1 comment · Fixed by #1677
Closed

datetime.utcfromtimestamp() and .utcnow() are deprecated #1675

ThomasWaldmann opened this issue Apr 5, 2024 · 1 comment · Fixed by #1677
Assignees
Milestone

Comments

@ThomasWaldmann
Copy link
Member

ThomasWaldmann commented Apr 5, 2024

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:

https://docs.python.org/3/library/datetime.html#datetime.datetime.fromtimestamp

@ThomasWaldmann ThomasWaldmann added this to the 2.0.0b1 milestone Apr 5, 2024
@ThomasWaldmann
Copy link
Member Author

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)

@ThomasWaldmann ThomasWaldmann self-assigned this Apr 6, 2024
@ThomasWaldmann ThomasWaldmann changed the title datetime.utcfromtimestamp() is deprecated datetime.utcfromtimestamp() and .utcnow() are deprecated Apr 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant