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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Samk13
Copy link
Member

@Samk13 Samk13 commented May 2, 2024

❤️ 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.

@Samk13 Samk13 force-pushed the remove-deprecated-utcnow branch 2 times, most recently from f1780d7 to e570fd3 Compare October 14, 2024 21:50
…ne.utc)

* Updated datetime.utcnow() to datetime.now(timezone.utc) following its deprecated since version 3.12.
* See <https://docs.python.org/3/library/datetime.html#datetime.datetime.utcnow>
* A decision should be made whether to keep naive datetime objects or switch to timezone-aware datetimes.
@Samk13 Samk13 force-pushed the remove-deprecated-utcnow branch from e570fd3 to 08c8e60 Compare October 14, 2024 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: To review
Development

Successfully merging this pull request may close these issues.

1 participant