예제 #1
0
    def matchinstance(self, component, instances):
        """
        Test whether this time-range element causes a match to the specified component
        using the specified set of instances to determine the expanded time ranges.
        @param component: the L{Component} to test.
        @param instances: the list of expanded instances.
        @return: True if the time-range query matches, False otherwise.
        """
        if component is None:
            return False

        assert instances is not None or self.end is None, "Failure to expand instance for time-range filter: %r" % (
            self, )

        # Special case open-ended unbounded
        if instances is None:
            if component.getRecurrenceIDUTC() is None:
                return True
            else:
                # See if the overridden component's start is past the start
                start, _ignore_end = component.getEffectiveStartEnd()
                if start is None:
                    return True
                else:
                    return start >= self.start

        # Handle alarms as a special case
        alarms = (component.name() == "VALARM")
        if alarms:
            testcomponent = component._parent
        else:
            testcomponent = component

        for key in instances:
            instance = instances[key]

            # First make sure components match
            if not testcomponent.same(instance.component):
                continue

            if alarms:
                # Get all the alarm triggers for this instance and test each one
                triggers = instance.getAlarmTriggers()
                for trigger in triggers:
                    if timeRangesOverlap(trigger, None, self.start, self.end,
                                         self.tzinfo):
                        return True
            else:
                # Regular instance overlap test
                if timeRangesOverlap(instance.start, instance.end, self.start,
                                     self.end, self.tzinfo):
                    return True

        return False
    def matchinstance(self, component, instances):
        """
        Test whether this time-range element causes a match to the specified component
        using the specified set of instances to determine the expanded time ranges.
        @param component: the L{Component} to test.
        @param instances: the list of expanded instances.
        @return: True if the time-range query matches, False otherwise.
        """
        if component is None:
            return False
        
        assert instances is not None or self.end is None, "Failure to expand instance for time-range filter: %r" % (self,)
        
        # Special case open-ended unbounded
        if instances is None:
            if component.getRecurrenceIDUTC() is None:
                return True
            else:
                # See if the overridden component's start is past the start
                start, _ignore_end = component.getEffectiveStartEnd()
                if start is None:
                    return True
                else:
                    return start >= self.start

        # Handle alarms as a special case
        alarms = (component.name() == "VALARM")
        if alarms:
            testcomponent = component._parent
        else:
            testcomponent = component
            
        for key in instances:
            instance = instances[key]
            
            # First make sure components match
            if not testcomponent.same(instance.component):
                continue

            if alarms:
                # Get all the alarm triggers for this instance and test each one
                triggers = instance.getAlarmTriggers()
                for trigger in triggers:
                    if timeRangesOverlap(trigger, None, self.start, self.end, self.tzinfo):
                        return True
            else:
                # Regular instance overlap test
                if timeRangesOverlap(instance.start, instance.end, self.start, self.end, self.tzinfo):
                    return True

        return False
예제 #3
0
    def processFreeBusyFreeBusy(self, calendar, fbinfo):
        """
        Extract FREEBUSY data from a VFREEBUSY component.
        @param calendar: the L{Component} that is the VCALENDAR containing the VFREEBUSY's.
        @param fbinfo: the tuple used to store the three types of fb data.
        """

        for vfb in [x for x in calendar.subcomponents() if x.name() == "VFREEBUSY"]:
            # First check any start/end in the actual component
            start = vfb.getStartDateUTC()
            end = vfb.getEndDateUTC()
            if start and end:
                if not timeRangesOverlap(start, end, self.timerange.getStart(), self.timerange.getEnd()):
                    continue

            # Now look at each FREEBUSY property
            for fb in vfb.properties("FREEBUSY"):
                # Check the type
                fbtype = fb.parameterValue("FBTYPE", default="BUSY")
                if fbtype == "FREE":
                    continue

                # Look at each period in the property
                assert isinstance(fb.value(), list), "FREEBUSY property does not contain a list of values: %r" % (fb,)
                for period in fb.value():
                    # Clip period for this instance
                    clipped = clipPeriod(period.getValue(), self.timerange)
                    if clipped:
                        getattr(fbinfo, self.FBInfo_mapper.get(fbtype, "busy")).append(clipped)
예제 #4
0
def processFreeBusyFreeBusy(calendar, fbinfo, timerange):
    """
    Extract FREEBUSY data from a VFREEBUSY component.
    @param calendar: the L{Component} that is the VCALENDAR containing the VFREEBUSY's.
    @param fbinfo: the tuple used to store the three types of fb data.
    @param timerange: the time range to restrict free busy data to.
    """

    for vfb in [x for x in calendar.subcomponents() if x.name() == "VFREEBUSY"]:
        # First check any start/end in the actual component
        start = vfb.getStartDateUTC()
        end = vfb.getEndDateUTC()
        if start and end:
            if not timeRangesOverlap(start, end, timerange.start, timerange.end):
                continue

        # Now look at each FREEBUSY property
        for fb in vfb.properties("FREEBUSY"):
            # Check the type
            fbtype = fb.parameterValue("FBTYPE", default="BUSY")
            if fbtype == "FREE":
                continue

            # Look at each period in the property
            assert isinstance(fb.value(), list), "FREEBUSY property does not contain a list of values: %r" % (fb,)
            for period in fb.value():
                # Clip period for this instance
                clipped = clipPeriod(period.getValue(), PyCalendarPeriod(timerange.start, timerange.end))
                if clipped:
                    fbinfo[fbtype_mapper.get(fbtype, 0)].append(clipped)
예제 #5
0
    def test_timeRangesOverlap(self):

        data = (
            # Timed
            (
                "Start within, end within - overlap",
                DateTime(2012, 1, 1, 11, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 1, 12, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 1, 0, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 2, 0, 0, 0, tzid=Timezone.UTCTimezone),
                True,
            ),
            (
                "Start before, end before - no overlap",
                DateTime(2012, 1, 1, 11, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 1, 12, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 2, 0, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 3, 0, 0, 0, tzid=Timezone.UTCTimezone),
                False,
            ),
            (
                "Start before, end right before - no overlap",
                DateTime(2012, 1, 1, 23, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 2, 0, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 2, 0, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 3, 0, 0, 0, tzid=Timezone.UTCTimezone),
                False,
            ),
            (
                "Start before, end within - overlap",
                DateTime(2012, 1, 1, 11, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 2, 11, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 2, 0, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 3, 0, 0, 0, tzid=Timezone.UTCTimezone),
                True,
            ),
            (
                "Start after, end after - no overlap",
                DateTime(2012, 1, 2, 11, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 2, 12, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 1, 0, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 2, 0, 0, 0, tzid=Timezone.UTCTimezone),
                False,
            ),
            (
                "Start right after, end after - no overlap",
                DateTime(2012, 1, 2, 0, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 2, 1, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 1, 0, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 2, 0, 0, 0, tzid=Timezone.UTCTimezone),
                False,
            ),
            (
                "Start within, end after - overlap",
                DateTime(2012, 1, 1, 12, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 2, 12, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 1, 0, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 2, 0, 0, 0, tzid=Timezone.UTCTimezone),
                True,
            ),
            (
                "Start before, end after - overlap",
                DateTime(2012, 1, 1, 11, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 3, 11, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 2, 0, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 3, 0, 0, 0, tzid=Timezone.UTCTimezone),
                True,
            ),

            # All day
            (
                "All day: Start within, end within - overlap",
                DateTime(2012, 1, 9),
                DateTime(2012, 1, 10),
                DateTime(2012, 1, 8, 0, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 15, 0, 0, 0, tzid=Timezone.UTCTimezone),
                True,
            ),
            (
                "All day: Start before, end before - no overlap",
                DateTime(2012, 1, 1),
                DateTime(2012, 1, 2),
                DateTime(2012, 1, 8, 0, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 15, 0, 0, 0, tzid=Timezone.UTCTimezone),
                False,
            ),
            (
                "All day: Start before, end right before - no overlap",
                DateTime(2012, 1, 7),
                DateTime(2012, 1, 8),
                DateTime(2012, 1, 8, 0, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 15, 0, 0, 0, tzid=Timezone.UTCTimezone),
                False,
            ),
            (
                "All day: Start before, end within - overlap",
                DateTime(2012, 1, 7),
                DateTime(2012, 1, 9),
                DateTime(2012, 1, 8, 0, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 15, 0, 0, 0, tzid=Timezone.UTCTimezone),
                True,
            ),
            (
                "All day: Start after, end after - no overlap",
                DateTime(2012, 1, 16),
                DateTime(2012, 1, 17),
                DateTime(2012, 1, 8, 0, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 15, 0, 0, 0, tzid=Timezone.UTCTimezone),
                False,
            ),
            (
                "All day: Start right after, end after - no overlap",
                DateTime(2012, 1, 15),
                DateTime(2012, 1, 16),
                DateTime(2012, 1, 8, 0, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 15, 0, 0, 0, tzid=Timezone.UTCTimezone),
                False,
            ),
            (
                "All day: Start within, end after - overlap",
                DateTime(2012, 1, 14),
                DateTime(2012, 1, 16),
                DateTime(2012, 1, 8, 0, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 15, 0, 0, 0, tzid=Timezone.UTCTimezone),
                True,
            ),
            (
                "All day: Start before, end after - overlap",
                DateTime(2012, 1, 7),
                DateTime(2012, 1, 16),
                DateTime(2012, 1, 8, 0, 0, 0, tzid=Timezone.UTCTimezone),
                DateTime(2012, 1, 15, 0, 0, 0, tzid=Timezone.UTCTimezone),
                True,
            ),
        )

        for title, start1, end1, start2, end2, result in data:
            self.assertEqual(timeRangesOverlap(start1, end1, start2, end2),
                             result,
                             msg="Failed: %s" % (title, ))
예제 #6
0
 def test_timeRangesOverlap(self):
     
     data = (
         # Timed
         (
             "Start within, end within - overlap",
             PyCalendarDateTime(2012, 1, 1, 11, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 1, 12, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 1, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 2, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             True,
         ),
         (
             "Start before, end before - no overlap",
             PyCalendarDateTime(2012, 1, 1, 11, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 1, 12, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 2, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 3, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             False,
         ),
         (
             "Start before, end right before - no overlap",
             PyCalendarDateTime(2012, 1, 1, 23, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 2, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 2, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 3, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             False,
         ),
         (
             "Start before, end within - overlap",
             PyCalendarDateTime(2012, 1, 1, 11, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 2, 11, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 2, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 3, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             True,
         ),
         (
             "Start after, end after - no overlap",
             PyCalendarDateTime(2012, 1, 2, 11, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 2, 12, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 1, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 2, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             False,
         ),
         (
             "Start right after, end after - no overlap",
             PyCalendarDateTime(2012, 1, 2, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 2, 1, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 1, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 2, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             False,
         ),
         (
             "Start within, end after - overlap",
             PyCalendarDateTime(2012, 1, 1, 12, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 2, 12, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 1, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 2, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             True,
         ),
         (
             "Start before, end after - overlap",
             PyCalendarDateTime(2012, 1, 1, 11, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 3, 11, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 2, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 3, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             True,
         ),
         
         # All day
         (
             "All day: Start within, end within - overlap",
             PyCalendarDateTime(2012, 1, 9),
             PyCalendarDateTime(2012, 1, 10),
             PyCalendarDateTime(2012, 1, 8, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 15, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             True,
         ),
         (
             "All day: Start before, end before - no overlap",
             PyCalendarDateTime(2012, 1, 1),
             PyCalendarDateTime(2012, 1, 2),
             PyCalendarDateTime(2012, 1, 8, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 15, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             False,
         ),
         (
             "All day: Start before, end right before - no overlap",
             PyCalendarDateTime(2012, 1, 7),
             PyCalendarDateTime(2012, 1, 8),
             PyCalendarDateTime(2012, 1, 8, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 15, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             False,
         ),
         (
             "All day: Start before, end within - overlap",
             PyCalendarDateTime(2012, 1, 7),
             PyCalendarDateTime(2012, 1, 9),
             PyCalendarDateTime(2012, 1, 8, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 15, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             True,
         ),
         (
             "All day: Start after, end after - no overlap",
             PyCalendarDateTime(2012, 1, 16),
             PyCalendarDateTime(2012, 1, 17),
             PyCalendarDateTime(2012, 1, 8, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 15, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             False,
         ),
         (
             "All day: Start right after, end after - no overlap",
             PyCalendarDateTime(2012, 1, 15),
             PyCalendarDateTime(2012, 1, 16),
             PyCalendarDateTime(2012, 1, 8, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 15, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             False,
         ),
         (
             "All day: Start within, end after - overlap",
             PyCalendarDateTime(2012, 1, 14),
             PyCalendarDateTime(2012, 1, 16),
             PyCalendarDateTime(2012, 1, 8, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 15, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             True,
         ),
         (
             "All day: Start before, end after - overlap",
             PyCalendarDateTime(2012, 1, 7),
             PyCalendarDateTime(2012, 1, 16),
             PyCalendarDateTime(2012, 1, 8, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             PyCalendarDateTime(2012, 1, 15, 0, 0, 0, tzid=PyCalendarTimezone(utc=True)),
             True,
         ),
     )
     
     for title, start1, end1, start2, end2, result in data:
         self.assertEqual(timeRangesOverlap(start1, end1, start2, end2), result, msg="Failed: %s" % (title,))