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

Codemod to add tz=UTC to any datetime function without a timezone #385

Open
clavedeluna opened this issue Mar 18, 2024 · 4 comments
Open
Labels
new-codemod Description for a new codemod

Comments

@clavedeluna
Copy link
Contributor

A while ago I discovered this flake8 datetime plugin which if installed warns you if you use something like datetime.datetime() (and others in the page). As is, the timezone used is whatever timezone the machine that runs the code is using. This may be okay in some cases, but it can lead to bugs. And misinterpretation of dates have been the culprit for serious issues in banking, satellites, Y2K fiasco, etc. So this is really important.

My suggestion for this codemod is to add a tz=UTC parameter to force code to run in UTC time. The big downside here is if the machine that ran the code previously was using a different timezone, crashes or bugs can happen on the first run. But the big advantage here is that it will force developers to think about which timezone they need.

@clavedeluna clavedeluna added the new-codemod Description for a new codemod label Mar 18, 2024
@drdavella
Copy link
Member

@clavedeluna this is an interesting idea. I wonder whether this overlaps at all with #368?

@clavedeluna clavedeluna self-assigned this May 1, 2024
@clavedeluna
Copy link
Contributor Author

Also add the sonar rule as a sonar codemo
https://rules.sonarsource.com/python/RSPEC-6903/

@clavedeluna
Copy link
Contributor Author

I made quite a bit of progress in this branch but due to other work needs I'm going to unassign this for now.

@clavedeluna
Copy link
Contributor Author

After completing [https://github.com//pull/802]) we should add all remaining functions listed in the flake8 plugin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-codemod Description for a new codemod
Projects
None yet
Development

No branches or pull requests

2 participants