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

Fix DeprecationWarning: datetime.datetime.utcnow() #8510

Open
jeffschaller opened this issue Nov 2, 2023 · 1 comment · Fixed by #8552
Open

Fix DeprecationWarning: datetime.datetime.utcnow() #8510

jeffschaller opened this issue Nov 2, 2023 · 1 comment · Fixed by #8552
Assignees
Labels
type: enhancement Improvements which don't reach the level of being new features.

Comments

@jeffschaller
Copy link
Contributor

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()

@jeffschaller jeffschaller added the type: enhancement Improvements which don't reach the level of being new features. label Nov 2, 2023
@jeffschaller jeffschaller self-assigned this Nov 2, 2023
@jeffschaller
Copy link
Contributor Author

jeffschaller commented Nov 4, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Improvements which don't reach the level of being new features.
1 participant