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:
- changing
from datetime import datetime
tofrom datetime import datetime, timezone
- changing all instances of
datetime.utcnow()
todatetime.now(tz=timezone.utc)
Currently working on this on a branch, and will submit a PR when it's ready