Skip to content

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

Description

@clavedeluna

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.

Activity

  1. drdavella commented on Mar 19, 2024

    @drdavella
    Contributor

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

  2. self-assigned this
    on May 1, 2024
  3. clavedeluna commented on May 6, 2024

    @clavedeluna
    ContributorAuthor

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

  4. clavedeluna commented on May 6, 2024

    @clavedeluna
    ContributorAuthor

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

  5. removed their assignment
    on May 6, 2024
  6. clavedeluna commented on Aug 19, 2024

    @clavedeluna
    ContributorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    new-codemodDescription for a new codemod

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions