Charcoal-SE / SmokeDetector

Headless chatbot that detects spam and posts links to it in chatrooms for quick deletion.

Home Page:https://metasmoke.erwaysoftware.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fix DeprecationWarning: datetime.datetime.utcnow()

jeffschaller opened this issue · comments

Is your feature request related to a problem? Please describe.

Builds sometimes output a deprecation warning; for example: https://github.com/Charcoal-SE/SmokeDetector/actions/runs/6731552476/job/18296462660#step:10:65

Describe the solution you'd like

It looks like there's a suggested alternative: "Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC)."

Describe alternatives you've considered

No other alternatives at this time.

Additional context

globalvars.py:84
/home/runner/work/SmokeDetector/SmokeDetector/globalvars.py:84: 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).
startup_utc_date = datetime.utcnow()

It looks like the fix consists of:

  1. changing from datetime import datetime to from datetime import datetime, timezone
  2. changing all instances of datetime.utcnow() to datetime.now(tz=timezone.utc)

Currently working on this on a branch, and will submit a PR when it's ready