# HG changeset patch # User Paul Boddie # Date 1512334794 -3600 # Node ID d1f864ab0a165810e1ab3ba843dd75748a86a7de # Parent 9b6843537c2fbd0d56f838171a90973e2167512c Introduced symbols for resolution levels and a mapping from levels to symbols. diff -r 9b6843537c2f -r d1f864ab0a16 vRecurrence.py --- a/vRecurrence.py Sun Dec 03 19:50:50 2017 +0100 +++ b/vRecurrence.py Sun Dec 03 21:59:54 2017 +0100 @@ -75,6 +75,23 @@ YEARS, MONTHS, WEEKS, DAYS, HOURS, MINUTES, SECONDS = 0, 1, 2, 5, 6, 7, 8 +# Special levels for day frequency qualifiers. + +YEARDAYS, MONTHDAYS = 3, 4 + +# Special levels used by non-qualifier-originating selectors. + +COUNT, DTSTART, BYSETPOS = -2, -1, None + +level_labels = ( + "YEARS", "MONTHS", "WEEKS", "YEARDAYS", "MONTHDAYS", "DAYS", "HOURS", + "MINUTES", "SECONDS", + + # Negative indexes. + + "COUNT", "DTSTART" + ) + # Enumeration levels, employed by BY... qualifiers. enum_levels = ( @@ -289,10 +306,10 @@ # Create a selector that must be updated with the maximum resolution. elif qualifier == "BYSETPOS": - return PositionSelector(None, args, "BYSETPOS") + return PositionSelector(BYSETPOS, args, "BYSETPOS") elif qualifier == "COUNT": - return LimitSelector(-2, args, "COUNT") + return LimitSelector(COUNT, args, "COUNT") else: return Pattern(freq[qualifier], args, qualifier) @@ -301,7 +318,7 @@ "Return a copy of 'selectors' incorporating 'dt'." - selectors = selectors + [StartSelector(-1, {"start" : dt}, "DTSTART")] + selectors = selectors + [StartSelector(DTSTART, {"start" : dt}, "DTSTART")] selectors.sort(key=selector_sort_key) return selectors @@ -871,7 +888,8 @@ self.first = first def __repr__(self): - return "%s(%r, %r, %r, %r)" % (self.__class__.__name__, self.level, + return "%s(%s, %r, %r, %r)" % (self.__class__.__name__, + level_labels[self.level], self.args, self.qualifier, self.first) def select(self, start, end, inclusive=False):