Jul 13 - Optimize code
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
"""Time helpers.
|
||||
|
||||
`datetime.utcnow()` is deprecated on Python 3.12+. This helper preserves the
|
||||
existing *naive UTC* semantics the codebase relies on (DB columns are naive
|
||||
`DateTime`, and comparisons assume naive UTC) while avoiding the deprecation:
|
||||
we build an aware UTC datetime and strip the tzinfo, yielding the exact same
|
||||
value `datetime.utcnow()` used to return.
|
||||
"""
|
||||
from datetime import datetime, timezone
|
||||
|
||||
|
||||
def utcnow() -> datetime:
|
||||
"""Current UTC time as a naive datetime (tzinfo stripped)."""
|
||||
return datetime.now(timezone.utc).replace(tzinfo=None)
|
||||
Reference in New Issue
Block a user