[CalendarServer-changes] [2994] CalendarServer/trunk/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Sat Sep 13 10:34:08 PDT 2008


Revision: 2994
          http://trac.macosforge.org/projects/calendarserver/changeset/2994
Author:   cdaboo at apple.com
Date:     2008-09-13 10:34:06 -0700 (Sat, 13 Sep 2008)
Log Message:
-----------
Make sure master DTSTART is not included as an instance if it has a corresponding EXDATE.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/instance.py
    CalendarServer/trunk/twistedcaldav/test/test_icalendar.py

Modified: CalendarServer/trunk/twistedcaldav/instance.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/instance.py	2008-09-12 19:46:40 UTC (rev 2993)
+++ CalendarServer/trunk/twistedcaldav/instance.py	2008-09-13 17:34:06 UTC (rev 2994)
@@ -270,7 +270,14 @@
             # dateutils does not do all-day - so convert to datetime.datetime
             start = normalizeForIndex(start)
             end = normalizeForIndex(end)
-            self.addInstance(Instance(component, start, end))
+            
+            # Do not add if in EXDATEs
+            exdates = []
+            for prop in component.properties("EXDATE"):
+                exdates.extend(prop.value())
+            exdates = [normalizeForIndex(exdate) for exdate in exdates]
+            if start not in exdates:
+                self.addInstance(Instance(component, start, end))
         else:
             self.limit = limit
         

Modified: CalendarServer/trunk/twistedcaldav/test/test_icalendar.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/test/test_icalendar.py	2008-09-12 19:46:40 UTC (rev 2993)
+++ CalendarServer/trunk/twistedcaldav/test/test_icalendar.py	2008-09-13 17:34:06 UTC (rev 2994)
@@ -1425,3 +1425,106 @@
             component = Component.fromString(original)
             component.removeAlarms()
             self.assertEqual(result, str(component).replace("\r", ""))
+
+    def test_expand_instances(self):
+        
+        data = (
+            (
+                "Non recurring",
+                """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//PYVOBJECT//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T000000Z
+DURATION:P1H
+END:VEVENT
+END:VCALENDAR
+""",
+                (datetime.datetime(2007, 11, 14, 0, 0, 0, tzinfo=tzutc()),)
+            ),
+            (
+                "Simple recurring",
+                """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//PYVOBJECT//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T000000Z
+DURATION:P1H
+RRULE:FREQ=DAILY;COUNT=2
+END:VEVENT
+END:VCALENDAR
+""",
+                (
+                    datetime.datetime(2007, 11, 14, 0, 0, 0, tzinfo=tzutc()),
+                    datetime.datetime(2007, 11, 15, 0, 0, 0, tzinfo=tzutc()),
+                )
+            ),
+            (
+                "Recurring with RDATE",
+                """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//PYVOBJECT//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T000000Z
+DURATION:P1H
+RRULE:FREQ=DAILY;COUNT=2
+RDATE:20071116T010000Z
+END:VEVENT
+END:VCALENDAR
+""",
+                (
+                    datetime.datetime(2007, 11, 14, 0, 0, 0, tzinfo=tzutc()),
+                    datetime.datetime(2007, 11, 15, 0, 0, 0, tzinfo=tzutc()),
+                    datetime.datetime(2007, 11, 16, 1, 0, 0, tzinfo=tzutc()),
+                )
+            ),
+            (
+                "Recurring with EXDATE",
+                """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//PYVOBJECT//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T000000Z
+DURATION:P1H
+RRULE:FREQ=DAILY;COUNT=3
+EXDATE:20071115T000000Z
+END:VEVENT
+END:VCALENDAR
+""",
+                (
+                    datetime.datetime(2007, 11, 14, 0, 0, 0, tzinfo=tzutc()),
+                    datetime.datetime(2007, 11, 16, 0, 0, 0, tzinfo=tzutc()),
+                )
+            ),
+            (
+                "Recurring with EXDATE on DTSTART",
+                """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//PYVOBJECT//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-1
+DTSTART:20071114T000000Z
+DURATION:P1H
+RRULE:FREQ=DAILY;COUNT=3
+EXDATE:20071114T000000Z
+END:VEVENT
+END:VCALENDAR
+""",
+                (
+                    datetime.datetime(2007, 11, 15, 0, 0, 0, tzinfo=tzutc()),
+                    datetime.datetime(2007, 11, 16, 0, 0, 0, tzinfo=tzutc()),
+                )
+            ),
+        )
+        
+        for description, original, results in data:
+            component = Component.fromString(original)
+            instances = component.expandTimeRanges(datetime.date(2100, 1, 1))
+            self.assertTrue(len(instances.instances) == len(results), "%s: wrong number of instances" % (description,))
+            for instance in instances:
+                self.assertTrue(instances[instance].start in results, "%s: %s missing" % (description, instance,))
+       
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080913/043e27da/attachment.html 


More information about the calendarserver-changes mailing list