MCPcopy Create free account
hub / github.com/dateutil/dateutil / test_ambiguous_and_imaginary

Function test_ambiguous_and_imaginary

tests/test_tzpath_data.py:97–116  ·  view source on GitHub ↗

datetime_ambiguous and datetime_exists agree with the fold offsets.

(tz_source)

Source from the content-addressed store, hash-verified

95
96
97def test_ambiguous_and_imaginary(tz_source):
98 """datetime_ambiguous and datetime_exists agree with the fold offsets."""
99 for key in _keys():
100 zone = tz.gettz(key)
101 for dt_utc in _probe_instants(zone):
102 local = dt_utc.astimezone(zone).replace(tzinfo=None)
103 # Local times an hour either side are more likely to land in a
104 # gap or a fold near a transition.
105 for wall in (
106 local - timedelta(hours=1),
107 local,
108 local + timedelta(hours=1),
109 ):
110 dt = wall.replace(tzinfo=zone)
111 offset_0 = tz.enfold(dt, fold=0).utcoffset()
112 offset_1 = tz.enfold(dt, fold=1).utcoffset()
113
114 case = (key, wall)
115 assert tz.datetime_ambiguous(dt) == (offset_0 > offset_1), case
116 assert tz.datetime_exists(dt) == (offset_0 >= offset_1), case
117
118
119def test_matches_zoneinfo(tz_source):

Callers

nothing calls this directly

Calls 5

_keysFunction · 0.85
_probe_instantsFunction · 0.85
replaceMethod · 0.80
gettzMethod · 0.45
utcoffsetMethod · 0.45

Tested by

no test coverage detected