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

Method __construct_byset

src/dateutil/rrule.py:1047–1092  ·  view source on GitHub ↗

If a `BYXXX` sequence is passed to the constructor at the same level as `FREQ` (e.g. `FREQ=HOURLY,BYHOUR={2,4,7},INTERVAL=3`), there are some specifications which cannot be reached given some starting conditions. This occurs whenever the interval is not coprime with

(self, start, byxxx, base)

Source from the content-addressed store, hash-verified

1045 ii.rebuild(year, month)
1046
1047 def __construct_byset(self, start, byxxx, base):
1048 """
1049 If a `BYXXX` sequence is passed to the constructor at the same level as
1050 `FREQ` (e.g. `FREQ=HOURLY,BYHOUR={2,4,7},INTERVAL=3`), there are some
1051 specifications which cannot be reached given some starting conditions.
1052
1053 This occurs whenever the interval is not coprime with the base of a
1054 given unit and the difference between the starting position and the
1055 ending position is not coprime with the greatest common denominator
1056 between the interval and the base. For example, with a FREQ of hourly
1057 starting at 17:00 and an interval of 4, the only valid values for
1058 BYHOUR would be {21, 1, 5, 9, 13, 17}, because 4 and 24 are not
1059 coprime.
1060
1061 :param start:
1062 Specifies the starting position.
1063 :param byxxx:
1064 An iterable containing the list of allowed values.
1065 :param base:
1066 The largest allowable value for the specified frequency (e.g.
1067 24 hours, 60 minutes).
1068
1069 This does not preserve the type of the iterable, returning a set, since
1070 the values should be unique and the order is irrelevant, this will
1071 speed up later lookups.
1072
1073 In the event of an empty set, raises a :exception:`ValueError`, as this
1074 results in an empty rrule.
1075 """
1076
1077 cset = set()
1078
1079 # Support a single byxxx value.
1080 if isinstance(byxxx, int):
1081 byxxx = (byxxx, )
1082
1083 for num in byxxx:
1084 i_gcd = math.gcd(self._interval, base)
1085 # Use divmod rather than % because we need to wrap negative nums.
1086 if i_gcd == 1 or divmod(num - start, i_gcd)[1] == 0:
1087 cset.add(num)
1088
1089 if len(cset) == 0:
1090 raise ValueError("Invalid rrule byxxx generates an empty set.")
1091
1092 return cset
1093
1094 def __mod_distance(self, value, byxxx, base):
1095 """

Callers 1

__init__Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected