MCPcopy Index your code
hub / github.com/RustPython/RustPython / construct_zone

Method construct_zone

Lib/test/test_zoneinfo/test_zoneinfo.py:826–942  ·  view source on GitHub ↗
(self, transitions, after=None, version=3)

Source from the content-addressed store, hash-verified

824 self.assertEqual(t.dst(), UTC.dst)
825
826 def construct_zone(self, transitions, after=None, version=3):
827 # These are not used for anything, so we're not going to include
828 # them for now.
829 isutc = []
830 isstd = []
831 leap_seconds = []
832
833 offset_lists = [[], []]
834 trans_times_lists = [[], []]
835 trans_idx_lists = [[], []]
836
837 v1_range = (-(2 ** 31), 2 ** 31)
838 v2_range = (-(2 ** 63), 2 ** 63)
839 ranges = [v1_range, v2_range]
840
841 def zt_as_tuple(zt):
842 # zt may be a tuple (timestamp, offset_before, offset_after) or
843 # a ZoneTransition object — this is to allow the timestamp to be
844 # values that are outside the valid range for datetimes but still
845 # valid 64-bit timestamps.
846 if isinstance(zt, tuple):
847 return zt
848
849 if zt.transition:
850 trans_time = int(zt.transition_utc.timestamp())
851 else:
852 trans_time = None
853
854 return (trans_time, zt.offset_before, zt.offset_after)
855
856 transitions = sorted(map(zt_as_tuple, transitions), key=lambda x: x[0])
857
858 for zt in transitions:
859 trans_time, offset_before, offset_after = zt
860
861 for v, (dt_min, dt_max) in enumerate(ranges):
862 offsets = offset_lists[v]
863 trans_times = trans_times_lists[v]
864 trans_idx = trans_idx_lists[v]
865
866 if trans_time is not None and not (
867 dt_min <= trans_time <= dt_max
868 ):
869 continue
870
871 if offset_before not in offsets:
872 offsets.append(offset_before)
873
874 if offset_after not in offsets:
875 offsets.append(offset_after)
876
877 if trans_time is not None:
878 trans_times.append(trans_time)
879 trans_idx.append(offsets.index(offset_after))
880
881 isutcnt = len(isutc)
882 isstdcnt = len(isstd)
883 leapcnt = len(leap_seconds)

Callers 7

test_one_transitionMethod · 0.95
test_one_zone_dstMethod · 0.95
test_no_tz_strMethod · 0.95
test_tz_before_onlyMethod · 0.95
test_empty_zoneMethod · 0.95

Calls 11

writeMethod · 0.95
seekMethod · 0.95
sortedFunction · 0.85
enumerateFunction · 0.85
lenFunction · 0.85
minFunction · 0.85
total_secondsMethod · 0.80
appendMethod · 0.45
indexMethod · 0.45
encodeMethod · 0.45
packMethod · 0.45

Tested by

no test coverage detected