Skip to content

Commit bcb032e

Browse files
authored
bpo-33810 Remove unused code from datetime.py. (GH-7549)
Since implementation of bpo-25283, the objects returned by time.localtime always have tm_zone and tm_gmtoff attributes. Remove code that anticipates their absence.
1 parent 4c3e39f commit bcb032e

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

Lib/datetime.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,17 +1759,10 @@ def _local_timezone(self):
17591759
ts = (self - _EPOCH) // timedelta(seconds=1)
17601760
localtm = _time.localtime(ts)
17611761
local = datetime(*localtm[:6])
1762-
try:
1763-
# Extract TZ data if available
1764-
gmtoff = localtm.tm_gmtoff
1765-
zone = localtm.tm_zone
1766-
except AttributeError:
1767-
delta = local - datetime(*_time.gmtime(ts)[:6])
1768-
zone = _time.strftime('%Z', localtm)
1769-
tz = timezone(delta, zone)
1770-
else:
1771-
tz = timezone(timedelta(seconds=gmtoff), zone)
1772-
return tz
1762+
# Extract TZ data
1763+
gmtoff = localtm.tm_gmtoff
1764+
zone = localtm.tm_zone
1765+
return timezone(timedelta(seconds=gmtoff), zone)
17731766

17741767
def astimezone(self, tz=None):
17751768
if tz is None:

0 commit comments

Comments
 (0)