diff options
author | Paul Ganssle <1377457+pganssle@users.noreply.github.com> | 2023-04-27 17:32:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-27 17:32:30 (GMT) |
commit | 0b7fd8ffc5df187edf8b5d926cee359924462df5 (patch) | |
tree | f88f8ba6dea519974bc2da3a4e18d69d07aefc8f /Lib/email | |
parent | a5308e188b810e5cc69c1570bdc9b21ed6c87805 (diff) | |
download | cpython-0b7fd8ffc5df187edf8b5d926cee359924462df5.zip cpython-0b7fd8ffc5df187edf8b5d926cee359924462df5.tar.gz cpython-0b7fd8ffc5df187edf8b5d926cee359924462df5.tar.bz2 |
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.
Diffstat (limited to 'Lib/email')
-rw-r--r-- | Lib/email/utils.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/Lib/email/utils.py b/Lib/email/utils.py index 4d014ba..81da539 100644 --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -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): |