FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-159706: Fix pure-Python ZoneInfo.fromutc() fold detection for single-transition zones by lazerg · Pull Request #159828 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
20 changes: 20 additions & 0 deletions Lib/test/test_zoneinfo/test_zoneinfo.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,26 @@ def test_one_transition(self):
dt_utc_actual = dt_local.astimezone(timezone.utc)
self.assertEqual(dt_utc_actual, dt_utc)

def test_one_transition_fold(self):
GMT = ZoneOffset("-00", ZERO)
N03 = ZoneOffset("-03", -timedelta(hours=3))

transitions = [
ZoneTransition(datetime(1976, 12, 1), GMT, N03),
]

after = "<-03>3"

zf = self.construct_zone(transitions, after)
zi = self.klass.from_file(zf)

dt_utc = datetime(1976, 12, 1, 1, tzinfo=timezone.utc)
dt_local = dt_utc.astimezone(zi)

self.assertEqual(dt_local.fold, 1)
self.assertEqual(dt_local.utcoffset(), N03.utcoffset)
self.assertEqual(dt_local.astimezone(timezone.utc), dt_utc)

def test_one_zone_dst(self):
DST = ZoneOffset("DST", ONE_H, ONE_H)
transitions = [
Expand Down
2 changes: 1 addition & 1 deletion Lib/zoneinfo/_zoneinfo.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def fromutc(self, dt):
if num_trans > 1 and timestamp >= self._trans_utc[1]:
tti_prev, tti = self._ttinfos[idx - 2 : idx]
elif timestamp > self._trans_utc[-1]:
tti_prev = self._ttinfos[-1]
tti_prev = self._tti_before
tti = self._tz_after
else:
tti_prev = self._tti_before
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix the pure-Python :class:`zoneinfo.ZoneInfo` setting ``fold=0`` in
:meth:`~datetime.tzinfo.fromutc` for times in the fold created by the only
transition of a zone with a single transition.
Loading

Back | FazBrowse Home | New Git URL