inveniosoftware / invenio-accounts

Invenio module for managing user accounts.
https://invenio-accounts.readthedocs.io
MIT License
6 stars 69 forks source link

refactor: replace deprecated datetime.utcnow with datetime.now(timezo… #480

Open Samk13 opened 6 months ago

Samk13 commented 6 months ago

:heart: Thank you for your contribution!

Description

Note:

A decision should be made whether to keep naive datetime objects or switch to timezone-aware datetimes. Using timezone-aware objects like datetime.now(timezone.utc) ensures future compatibility and avoids the upcoming deprecation of datetime.utcnow(). For now, this PR performs a drop-in replacement with datetime.now(timezone.utc).replace(tzinfo=None) to retain compatibility with the existing naive datetime usage, without altering the current behavior or implementation. Future revisions should consider full timezone awareness for better clarity and accuracy in time handling.

>>> from datetime import datetime, timezone
>>> print(datetime.now(timezone.utc))
2024-10-01 12:25:56.239591+00:00
>>> print(datetime.utcnow())
<stdin>:1: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
2024-10-01 12:26:08.612555
>>> print(datetime.now(timezone.utc).replace(tzinfo=None))
2024-10-01 12:27:28.583477

Once approved, we can proceed with updating the remaining packages.

Checklist

Ticks in all boxes and 🟢 on all GitHub actions status checks are required to merge:

Frontend

Reminder

By using GitHub, you have already agreed to the GitHub’s Terms of Service including that:

  1. You license your contribution under the same terms as the current repository’s license.
  2. You agree that you have the right to license your contribution under the current repository’s license.