Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Lib/test/test_zoneinfo/test_zoneinfo.py
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
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
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