| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,19 +13,17 @@ module: | |||
| 13 | 13 | ||
| 14 | 14 | .. function:: localtime(dt=None) | |
| 15 | 15 | ||
| 16 | - Return local time as an aware datetime object. If called without | ||
| 17 | - arguments, return current time. Otherwise *dt* argument should be a | ||
| 18 | - :class:`~datetime.datetime` instance, and it is converted to the local time | ||
| 19 | - zone according to the system time zone database. If *dt* is naive (that | ||
| 20 | - is, ``dt.tzinfo`` is ``None``), it is assumed to be in local time. In this | ||
| 21 | - case, a positive or zero value for *isdst* causes ``localtime`` to presume | ||
| 22 | - initially that summer time (for example, Daylight Saving Time) is or is not | ||
| 23 | - (respectively) in effect for the specified time. A negative value for | ||
| 24 | - *isdst* causes the ``localtime`` to attempt to divine whether summer time | ||
| 25 | - is in effect for the specified time. | ||
| 26 | - | ||
| 27 | - .. versionadded:: 3.3 | ||
| 16 | + Return local time as an aware datetime object. If called without | ||
| 17 | + arguments, return current time. Otherwise *dt* argument should be a | ||
| 18 | + :class:`~datetime.datetime` instance, and it is converted to the local time | ||
| 19 | + zone according to the system time zone database. If *dt* is naive (that | ||
| 20 | + is, ``dt.tzinfo`` is ``None``), it is assumed to be in local time. The | ||
| 21 | + *isdst* parameter is ignored. | ||
| 28 | 22 | ||
| 23 | + .. versionadded:: 3.3 | ||
| 24 | + | ||
| 25 | + .. deprecated-removed:: 3.12 3.14 | ||
| 26 | + The *isdst* parameter. | ||
| 29 | 27 | ||
| 30 | 28 | .. function:: make_msgid(idstring=None, domain=None) | |
| 31 | 29 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -565,6 +565,9 @@ Pending Removal in Python 3.14 | |||
| 565 | 565 | * Creating :c:data:`immutable types <Py_TPFLAGS_IMMUTABLETYPE>` with mutable | |
| 566 | 566 | bases using the C API. | |
| 567 | 567 | ||
| 568 | + * Deprecated the *isdst* parameter in :func:`email.utils.localtime`. | ||
| 569 | + (Contributed by Alan Williams in :gh:`72346`.) | ||
| 570 | + | ||
| 568 | 571 | * ``__package__`` and ``__cached__`` will cease to be set or taken | |
| 569 | 572 | into consideration by the import system (:gh:`97879`). | |
| 570 | 573 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -331,41 +331,23 @@ def collapse_rfc2231_value(value, errors='replace', | |||
| 331 | 331 | # better than not having it. | |
| 332 | 332 | # | |
| 333 | 333 | ||
| 334 | - def localtime(dt=None, isdst=-1): | ||
| 334 | + def localtime(dt=None, isdst=None): | ||
| 335 | 335 | """Return local time as an aware datetime object. | |
| 336 | 336 | ||
| 337 | 337 | If called without arguments, return current time. Otherwise *dt* | |
| 338 | 338 | argument should be a datetime instance, and it is converted to the | |
| 339 | 339 | local time zone according to the system time zone database. If *dt* is | |
| 340 | 340 | naive (that is, dt.tzinfo is None), it is assumed to be in local time. | |
| 341 | - In this case, a positive or zero value for *isdst* causes localtime to | ||
| 342 | - presume initially that summer time (for example, Daylight Saving Time) | ||
| 343 | - is or is not (respectively) in effect for the specified time. A | ||
| 344 | - negative value for *isdst* causes the localtime() function to attempt | ||
| 345 | - to divine whether summer time is in effect for the specified time. | ||
| 341 | + The isdst parameter is ignored. | ||
| 346 | 342 | ||
| 347 | 343 | """ | |
| 344 | + if isdst is not None: | ||
| 345 | + import warnings | ||
| 346 | + warnings._deprecated( | ||
| 347 | + "The 'isdst' parameter to 'localtime'", | ||
| 348 | + message='{name} is deprecated and slated for removal in Python {remove}', | ||
| 349 | + remove=(3, 14), | ||
| 350 | + ) | ||
| 348 | 351 | if dt is None: | |
| 349 | - return datetime.datetime.now(datetime.timezone.utc).astimezone() | ||
| 350 | - if dt.tzinfo is not None: | ||
| 351 | - return dt.astimezone() | ||
| 352 | - # We have a naive datetime. Convert to a (localtime) timetuple and pass to | ||
| 353 | - # system mktime together with the isdst hint. System mktime will return | ||
| 354 | - # seconds since epoch. | ||
| 355 | - tm = dt.timetuple()[:-1] + (isdst,) | ||
| 356 | - seconds = time.mktime(tm) | ||
| 357 | - localtm = time.localtime(seconds) | ||
| 358 | - try: | ||
| 359 | - delta = datetime.timedelta(seconds=localtm.tm_gmtoff) | ||
| 360 | - tz = datetime.timezone(delta, localtm.tm_zone) | ||
| 361 | - except AttributeError: | ||
| 362 | - # Compute UTC offset and compare with the value implied by tm_isdst. | ||
| 363 | - # If the values match, use the zone name implied by tm_isdst. | ||
| 364 | - delta = dt - datetime.datetime(*time.gmtime(seconds)[:6]) | ||
| 365 | - dst = time.daylight and localtm.tm_isdst > 0 | ||
| 366 | - gmtoff = -(time.altzone if dst else time.timezone) | ||
| 367 | - if delta == datetime.timedelta(seconds=gmtoff): | ||
| 368 | - tz = datetime.timezone(delta, time.tzname[dst]) | ||
| 369 | - else: | ||
| 370 | - tz = datetime.timezone(delta) | ||
| 371 | - return dt.replace(tzinfo=tz) | ||
| 352 | + dt = datetime.datetime.now() | ||
| 353 | + return dt.astimezone() | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -83,30 +83,30 @@ def test_localtime_is_tz_aware_daylight_false(self): | |||
| 83 | 83 | def test_localtime_daylight_true_dst_false(self): | |
| 84 | 84 | test.support.patch(self, time, 'daylight', True) | |
| 85 | 85 | t0 = datetime.datetime(2012, 3, 12, 1, 1) | |
| 86 | - t1 = utils.localtime(t0, isdst=-1) | ||
| 86 | + t1 = utils.localtime(t0) | ||
| 87 | 87 | t2 = utils.localtime(t1) | |
| 88 | 88 | self.assertEqual(t1, t2) | |
| 89 | 89 | ||
| 90 | 90 | def test_localtime_daylight_false_dst_false(self): | |
| 91 | 91 | test.support.patch(self, time, 'daylight', False) | |
| 92 | 92 | t0 = datetime.datetime(2012, 3, 12, 1, 1) | |
| 93 | - t1 = utils.localtime(t0, isdst=-1) | ||
| 93 | + t1 = utils.localtime(t0) | ||
| 94 | 94 | t2 = utils.localtime(t1) | |
| 95 | 95 | self.assertEqual(t1, t2) | |
| 96 | 96 | ||
| 97 | 97 | @test.support.run_with_tz('Europe/Minsk') | |
| 98 | 98 | def test_localtime_daylight_true_dst_true(self): | |
| 99 | 99 | test.support.patch(self, time, 'daylight', True) | |
| 100 | 100 | t0 = datetime.datetime(2012, 3, 12, 1, 1) | |
| 101 | - t1 = utils.localtime(t0, isdst=1) | ||
| 101 | + t1 = utils.localtime(t0) | ||
| 102 | 102 | t2 = utils.localtime(t1) | |
| 103 | 103 | self.assertEqual(t1, t2) | |
| 104 | 104 | ||
| 105 | 105 | @test.support.run_with_tz('Europe/Minsk') | |
| 106 | 106 | def test_localtime_daylight_false_dst_true(self): | |
| 107 | 107 | test.support.patch(self, time, 'daylight', False) | |
| 108 | 108 | t0 = datetime.datetime(2012, 3, 12, 1, 1) | |
| 109 | - t1 = utils.localtime(t0, isdst=1) | ||
| 109 | + t1 = utils.localtime(t0) | ||
| 110 | 110 | t2 = utils.localtime(t1) | |
| 111 | 111 | self.assertEqual(t1, t2) | |
| 112 | 112 | ||
@@ -157,6 +157,11 @@ def test_variable_tzname(self): | |||
| 157 | 157 | t1 = utils.localtime(t0) | |
| 158 | 158 | self.assertEqual(t1.tzname(), 'EET') | |
| 159 | 159 | ||
| 160 | + def test_isdst_deprecation(self): | ||
| 161 | + with self.assertWarns(DeprecationWarning): | ||
| 162 | + t0 = datetime.datetime(1990, 1, 1) | ||
| 163 | + t1 = utils.localtime(t0, isdst=True) | ||
| 164 | + | ||
| 160 | 165 | # Issue #24836: The timezone files are out of date (pre 2011k) | |
| 161 | 166 | # on Mac OS X Snow Leopard. | |
| 162 | 167 | @test.support.requires_mac_ver(10, 7) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + Added deprecation warning to *isdst* parameter of :func:`email.utils.localtime`. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments