From 0c1c2757efd8890944f155d142f58ce712371575 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Sun, 25 Aug 2013 12:35:41 +0200 Subject: [PATCH] Skip dupes in freebusy list --- plugins/libcalendaring/libvcalendar.php | 10 ++++-- plugins/libcalendaring/tests/libvcalendar.php | 4 +-- .../tests/resources/freebusy.ifb | 36 ------------------- 3 files changed, 9 insertions(+), 41 deletions(-) diff --git a/plugins/libcalendaring/libvcalendar.php b/plugins/libcalendaring/libvcalendar.php index 271f331e..998ed139 100644 --- a/plugins/libcalendaring/libvcalendar.php +++ b/plugins/libcalendaring/libvcalendar.php @@ -172,8 +172,7 @@ class libvcalendar } } else if ($ve->name == 'VFREEBUSY') { - $this->_parse_freebusy($ve); - break; + $this->objects[] = $this->_parse_freebusy($ve); } } } @@ -454,7 +453,8 @@ class libvcalendar */ private function _parse_freebusy($ve) { - $this->freebusy = array('periods' => array()); + $this->freebusy = array('_type' => 'freebusy', 'periods' => array()); + $seen = array(); foreach ($ve->children as $prop) { if (!($prop instanceof VObject\Property)) @@ -476,6 +476,10 @@ class libvcalendar $periods = explode(',', $prop->value); $fbtype = strval($prop['FBTYPE']) ?: 'BUSY'; + // skip dupes + if ($seen[$prop->value.':'.$fbtype]++) + continue; + foreach ($periods as $period) { // Every period is formatted as [start]/[end]. The start is an // absolute UTC time, the end may be an absolute UTC time, or diff --git a/plugins/libcalendaring/tests/libvcalendar.php b/plugins/libcalendaring/tests/libvcalendar.php index bc93bab9..a2043384 100644 --- a/plugins/libcalendaring/tests/libvcalendar.php +++ b/plugins/libcalendaring/tests/libvcalendar.php @@ -138,8 +138,8 @@ class libvcalendar_test extends PHPUnit_Framework_TestCase $this->assertInstanceOf('DateTime', $freebusy['start'], "'start' property is DateTime object"); $this->assertInstanceOf('DateTime', $freebusy['end'], "'end' property is DateTime object"); - $this->assertEquals(50, count($freebusy['periods']), "Number of freebusy periods defined"); - $this->assertEquals(48, count($ical->get_busy_periods()), "Number of busy periods found"); + $this->assertEquals(11, count($freebusy['periods']), "Number of freebusy periods defined"); + $this->assertEquals(9, count($ical->get_busy_periods()), "Number of busy periods found"); } /** diff --git a/plugins/libcalendaring/tests/resources/freebusy.ifb b/plugins/libcalendaring/tests/resources/freebusy.ifb index 07476b29..4491942a 100644 --- a/plugins/libcalendaring/tests/resources/freebusy.ifb +++ b/plugins/libcalendaring/tests/resources/freebusy.ifb @@ -10,48 +10,12 @@ DTEND:20131122T140026Z FREEBUSY;FBTYPE=FREE:20130826T110000Z/20130826T150000Z FREEBUSY:20130826T110000Z/20130826T150000Z FREEBUSY:20130826T110000Z/20130826T150000Z -FREEBUSY:20130826T110000Z/20130826T150000Z -FREEBUSY:20130826T110000Z/20130826T150000Z -FREEBUSY:20130826T110000Z/20130826T150000Z -FREEBUSY:20130826T110000Z/20130826T150000Z -FREEBUSY:20130827T100000Z/20130827T160000Z -FREEBUSY:20130827T100000Z/20130827T160000Z -FREEBUSY:20130827T100000Z/20130827T160000Z -FREEBUSY:20130827T100000Z/20130827T160000Z -FREEBUSY:20130827T100000Z/20130827T160000Z -FREEBUSY:20130827T100000Z/20130827T160000Z FREEBUSY:20130827T100000Z/20130827T160000Z FREEBUSY:20130828T100000Z/20130828T120000Z FREEBUSY:20130828T100000Z/20130828T120000Z -FREEBUSY:20130828T100000Z/20130828T120000Z -FREEBUSY:20130828T100000Z/20130828T120000Z -FREEBUSY:20130828T100000Z/20130828T120000Z -FREEBUSY:20130828T100000Z/20130828T120000Z -FREEBUSY:20130828T100000Z/20130828T120000Z -FREEBUSY:20130830T090000Z/20130830T093000Z -FREEBUSY:20130830T090000Z/20130830T093000Z -FREEBUSY:20130830T090000Z/20130830T093000Z -FREEBUSY:20130830T090000Z/20130830T093000Z -FREEBUSY:20130830T090000Z/20130830T093000Z -FREEBUSY:20130830T090000Z/20130830T093000Z FREEBUSY:20130830T090000Z/20130830T093000Z FREEBUSY:20130830T093000Z/20130830T100000Z -FREEBUSY:20130830T093000Z/20130830T100000Z -FREEBUSY:20130830T093000Z/20130830T100000Z -FREEBUSY:20130830T093000Z/20130830T100000Z -FREEBUSY:20130830T093000Z/20130830T100000Z -FREEBUSY:20130830T093000Z/20130830T100000Z -FREEBUSY:20130830T093000Z/20130830T100000Z FREEBUSY:20130930T070000Z/20130930T160000Z -FREEBUSY:20130930T070000Z/20130930T160000Z -FREEBUSY:20130930T070000Z/20130930T160000Z -FREEBUSY:20130930T070000Z/20130930T160000Z -FREEBUSY:20130930T070000Z/20130930T160000Z -FREEBUSY:20130930T070000Z/20130930T160000Z -FREEBUSY:20130930T070000Z/20130930T160000Z -FREEBUSY:20131104T113000Z/20131104T160000Z -FREEBUSY:20131104T113000Z/20131104T160000Z -FREEBUSY:20131104T113000Z/20131104T160000Z FREEBUSY:20131104T113000Z/20131104T160000Z FREEBUSY;FBTYPE=OOF:20131104T113000Z/20131104T160000Z FREEBUSY;FBTYPE=BUSY-TENTATIVE:20131104T113000Z/20131104T160000Z