Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

datetime-lint-action

Catch Python datetime bugs before they hit production.

What it detects

Code Issue Fix
DT001 datetime.utcnow() — deprecated, returns naive datetime datetime.now(timezone.utc)
DT002 datetime.now() — naive local time, breaks across timezones datetime.now(timezone.utc)
DT003 datetime.utcfromtimestamp() — deprecated, naive datetime.fromtimestamp(ts, tz=timezone.utc)
DT004 datetime.fromtimestamp() without tz= — naive local time Add tz=timezone.utc
DT005 .replace(tzinfo=None) — strips timezone, causes TypeError on comparison Keep timezone info

Why this matters

Naive/aware datetime mixing causes TypeError: can't compare offset-naive and offset-aware datetimes in production. It's one of Python's most common runtime errors and it's entirely preventable.

Usage

# .github/workflows/lint.yml
name: Datetime Lint
on: [pull_request]
jobs:
  datetime-lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: qwenbona/datetime-lint-action@v1
        with:
          path: 'src/'
          fail-on-warning: 'true'

Example output

::warning file=app/services/cache.py,line=42,title=DT001::datetime.utcnow() is deprecated...
::warning file=app/utils/helpers.py,line=18,title=DT002::datetime.now() without a timezone...

2 datetime issue(s) found across 47 files.

Local usage

python3 lint.py ./src

License

MIT

About

GitHub Action: catch Python datetime bugs (naive timestamps, deprecated utcnow, timezone comparison errors) before they hit production.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages