GH-103857: Deprecate utcnow and utcfromtimestamp (#103858)

Using `datetime.datetime.utcnow()` and `datetime.datetime.utcfromtimestamp()` will now raise a `DeprecationWarning`.

We also have removed our internal uses of these functions and documented the change.
This commit is contained in:
Paul Ganssle 2023-04-27 11:32:30 -06:00 committed by GitHub
parent a5308e188b
commit 0b7fd8ffc5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 101 additions and 34 deletions

View file

@ -143,13 +143,13 @@ def formatdate(timeval=None, localtime=False, usegmt=False):
# 2822 requires that day and month names be the English abbreviations.
if timeval is None:
timeval = time.time()
if localtime or usegmt:
dt = datetime.datetime.fromtimestamp(timeval, datetime.timezone.utc)
else:
dt = datetime.datetime.utcfromtimestamp(timeval)
dt = datetime.datetime.fromtimestamp(timeval, datetime.timezone.utc)
if localtime:
dt = dt.astimezone()
usegmt = False
elif not usegmt:
dt = dt.replace(tzinfo=None)
return format_datetime(dt, usegmt)
def format_datetime(dt, usegmt=False):