def expand()

in src/pycalendar/icalendar/recurrenceset.py [0:0]


    def expand(self, start, range, items, float_offset=0, maxInstances=None):
        # Need to return whether the limit was applied or not
        limited = False

        # Now create list of items to include
        include = []

        # Always include the initial DTSTART if within the range
        if range.isDateWithinPeriod(start):
            include.append(start)
        else:
            limited = True

        # RRULES
        for iter in self.mRrules:
            if iter.expand(start, range, include, float_offset=float_offset, maxInstances=maxInstances):
                limited = True

        # RDATES
        for iter in self.mRdates:
            if range.isDateWithinPeriod(iter):
                include.append(iter)
                if maxInstances and len(include) > maxInstances:
                    raise TooManyInstancesError("Too many instances")
            else:
                limited = True
        for iter in self.mRperiods:
            if range.isPeriodOverlap(iter):
                include.append(iter.getStart())
                if maxInstances and len(include) > maxInstances:
                    raise TooManyInstancesError("Too many instances")
            else:
                limited = True

        # Make sure the list is unique
        include = [x for x in set(include)]
        include.sort(key=lambda x: x.getPosixTime())

        # Now create list of items to exclude
        exclude = []

        # EXRULES
        for iter in self.mExrules:
            iter.expand(start, range, exclude, float_offset=float_offset)

        # EXDATES
        for iter in self.mExdates:
            if range.isDateWithinPeriod(iter):
                exclude.append(iter)
        for iter in self.mExperiods:
            if range.isPeriodOverlap(iter):
                exclude.append(iter.getStart())

        # Make sure the list is unique
        exclude = [x for x in set(exclude)]
        exclude.sort(key=lambda x: x.getPosixTime())

        # Add difference between to the two sets (include - exclude) to the
        # results
        items.extend(set_difference(include, exclude))
        return limited