mirror of
https://github.com/python/cpython.git
synced 2025-10-06 15:11:58 +00:00
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:
parent
a5308e188b
commit
0b7fd8ffc5
10 changed files with 101 additions and 34 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue