Skip to content

Remove usages of deprecated datetime.utcnow() and datetime.utcfromtimestamp()#765

Merged
Andrew-Chen-Wang merged 2 commits intojazzband:masterfrom
kozlek:master
Dec 4, 2023
Merged

Remove usages of deprecated datetime.utcnow() and datetime.utcfromtimestamp()#765
Andrew-Chen-Wang merged 2 commits intojazzband:masterfrom
kozlek:master

Conversation

@kozlek
Copy link
Copy Markdown
Contributor

@kozlek kozlek commented Nov 19, 2023

Changes:

  • removed usages of datetime.utcnow() and datetime.utcfromtimestamp()
  • added freezegun as test dependency to handle properly time patching during tests

Notes:

  • the chosen approach in this PR uses aware datetimes by default and downgrade to naive datetime if needed. Before it was the contrary.
  • aware_utcnow and datetime_from_epoch can still return naive datetime if settings.USE_TZ is False (original behaviour) -> we might want to force aware datetime in a future release
  • make_utc function has been kept but it is only used by our tests, not library code

Copy link
Copy Markdown
Member

@Andrew-Chen-Wang Andrew-Chen-Wang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

Copy link
Copy Markdown
Member

@50-Course 50-Course left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...aware_utcnow and datetime_from_epoch can still return naive datetime if settings.USE_TZ is False (original behaviour) -> we might want to force aware datetime in a future release

Thank you for this PR! Would be approving changes since, there is no breakage in library code.

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 this pull request may close these issues.

3 participants