summaryrefslogtreecommitdiffstats
path: root/Lib/email
diff options
context:
space:
mode:
authorAlan Williams <astropiloto@gmail.com>2023-03-20 00:20:20 (GMT)
committerGitHub <noreply@github.com>2023-03-20 00:20:20 (GMT)
commit5e6661bce968173fa45b74fa2111098645ff609c (patch)
tree15d81c86c066a70b5907be76d07d1b5d7ba62b44 /Lib/email
parent40d4f1579382a16d95ec67f2f03167bc1181dbd9 (diff)
downloadcpython-5e6661bce968173fa45b74fa2111098645ff609c.zip
cpython-5e6661bce968173fa45b74fa2111098645ff609c.tar.gz
cpython-5e6661bce968173fa45b74fa2111098645ff609c.tar.bz2
gh-72346: Added isdst deprecation warning to email.utils.localtime (GH-91450)
Diffstat (limited to 'Lib/email')
-rw-r--r--Lib/email/utils.py40
1 files changed, 11 insertions, 29 deletions
diff --git a/Lib/email/utils.py b/Lib/email/utils.py
index cfdfeb3..4d014ba 100644
--- a/Lib/email/utils.py
+++ b/Lib/email/utils.py
@@ -331,41 +331,23 @@ def collapse_rfc2231_value(value, errors='replace',
# better than not having it.
#
-def localtime(dt=None, isdst=-1):
+def localtime(dt=None, isdst=None):
"""Return local time as an aware datetime object.
If called without arguments, return current time. Otherwise *dt*
argument should be a datetime instance, and it is converted to the
local time zone according to the system time zone database. If *dt* is
naive (that is, dt.tzinfo is None), it is assumed to be in local time.
- In this case, a positive or zero value for *isdst* causes localtime to
- presume initially that summer time (for example, Daylight Saving Time)
- is or is not (respectively) in effect for the specified time. A
- negative value for *isdst* causes the localtime() function to attempt
- to divine whether summer time is in effect for the specified time.
+ The isdst parameter is ignored.
"""
+ if isdst is not None:
+ import warnings
+ warnings._deprecated(
+ "The 'isdst' parameter to 'localtime'",
+ message='{name} is deprecated and slated for removal in Python {remove}',
+ remove=(3, 14),
+ )
if dt is None:
- return datetime.datetime.now(datetime.timezone.utc).astimezone()
- if dt.tzinfo is not None:
- return dt.astimezone()
- # We have a naive datetime. Convert to a (localtime) timetuple and pass to
- # system mktime together with the isdst hint. System mktime will return
- # seconds since epoch.
- tm = dt.timetuple()[:-1] + (isdst,)
- seconds = time.mktime(tm)
- localtm = time.localtime(seconds)
- try:
- delta = datetime.timedelta(seconds=localtm.tm_gmtoff)
- tz = datetime.timezone(delta, localtm.tm_zone)
- except AttributeError:
- # Compute UTC offset and compare with the value implied by tm_isdst.
- # If the values match, use the zone name implied by tm_isdst.
- delta = dt - datetime.datetime(*time.gmtime(seconds)[:6])
- dst = time.daylight and localtm.tm_isdst > 0
- gmtoff = -(time.altzone if dst else time.timezone)
- if delta == datetime.timedelta(seconds=gmtoff):
- tz = datetime.timezone(delta, time.tzname[dst])
- else:
- tz = datetime.timezone(delta)
- return dt.replace(tzinfo=tz)
+ dt = datetime.datetime.now()
+ return dt.astimezone()