[Pkg-owncloud-commits] [php-sabre-vobject] 15/32: Testing reference timezone in recurrence expansion.

David Prévot taffit at moszumanska.debian.org
Fri Nov 28 22:27:09 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository php-sabre-vobject.

commit ce70a88c0f5a8b6bf5194763f71b8b7654786874
Author: Evert Pot <me at evertpot.com>
Date:   Wed Nov 12 20:22:41 2014 -0500

    Testing reference timezone in recurrence expansion.
---
 lib/Component/VCalendar.php                        |  2 +-
 lib/Recur/EventIterator.php                        | 21 ++++++--
 tests/VObject/Component/VCalendarTest.php          | 56 ++++++++++++++++++++--
 .../Recur/EventIterator/IncorrectExpandTest.php    |  1 -
 .../Recur/EventIterator/MissingOverriddenTest.php  |  1 -
 5 files changed, 72 insertions(+), 9 deletions(-)

diff --git a/lib/Component/VCalendar.php b/lib/Component/VCalendar.php
index af837a0..8704d33 100644
--- a/lib/Component/VCalendar.php
+++ b/lib/Component/VCalendar.php
@@ -273,7 +273,7 @@ class VCalendar extends VObject\Document {
                 throw new \LogicException('Event did not have a UID!');
             }
 
-            $it = new EventIterator($this, $vevent->uid);
+            $it = new EventIterator($this, $vevent->uid, $timeZone);
             $it->fastForward($start);
 
             while($it->valid() && $it->getDTStart() < $end) {
diff --git a/lib/Recur/EventIterator.php b/lib/Recur/EventIterator.php
index 8b14899..8743f5a 100644
--- a/lib/Recur/EventIterator.php
+++ b/lib/Recur/EventIterator.php
@@ -64,6 +64,13 @@ class EventIterator implements \Iterator {
     protected $timeZone;
 
     /**
+     * True if we're iterating an all-day event.
+     *
+     * @var bool
+     */
+    protected $allDay = false;
+
+    /**
      * Creates the iterator
      *
      * You should pass a VCALENDAR component, as well as the UID of the event
@@ -144,6 +151,7 @@ class EventIterator implements \Iterator {
             );
         }
         $this->startDate = $this->masterEvent->DTSTART->getDateTime($this->timeZone);
+        $this->allDay = !$this->masterEvent->DTSTART->hasTime();
 
         if (isset($this->masterEvent->EXDATE)) {
 
@@ -166,7 +174,7 @@ class EventIterator implements \Iterator {
             $end = clone $this->startDate;
             $end->add($duration);
             $this->eventDuration = $end->getTimeStamp() - $this->startDate->getTimeStamp();
-        } elseif ($this->masterEvent->DTSTART->getValueType() === 'DATE') {
+        } elseif ($this->allDay) {
             $this->eventDuration = 3600 * 24;
         } else {
             $this->eventDuration = 0;
@@ -276,8 +284,15 @@ class EventIterator implements \Iterator {
         if (isset($event->DTEND)) {
             $event->DTEND->setDateTime($this->getDtEnd());
         }
-        if ($this->recurIterator->key() > 0) {
-            $event->add('RECURRENCE-ID', $event->DTSTART->getDateTime());
+        // Including a RECURRENCE-ID to the object, unless this is the first
+        // object.
+        //
+        // The inner recurIterator is always one step ahead, this is why we're
+        // checking for the key being higher than 1.
+        if ($this->recurIterator->key() > 1) {
+            $recurid = clone $event->DTSTART;
+            $recurid->name = 'RECURRENCE-ID';
+            $event->add($recurid);
         }
         return $event;
 
diff --git a/tests/VObject/Component/VCalendarTest.php b/tests/VObject/Component/VCalendarTest.php
index 0b28124..2f4d21c 100644
--- a/tests/VObject/Component/VCalendarTest.php
+++ b/tests/VObject/Component/VCalendarTest.php
@@ -2,6 +2,7 @@
 
 namespace Sabre\VObject\Component;
 
+use DateTimeZone;
 use Sabre\VObject;
 
 class VCalendarTest extends \PHPUnit_Framework_TestCase {
@@ -9,13 +10,16 @@ class VCalendarTest extends \PHPUnit_Framework_TestCase {
     /**
      * @dataProvider expandData
      */
-    public function testExpand($input, $output) {
+    public function testExpand($input, $output, $timeZone = 'UTC', $start = '2011-12-01', $end = '2011-12-31') {
 
         $vcal = VObject\Reader::read($input);
 
+        $timeZone = new DateTimeZone($timeZone);
+
         $vcal->expand(
-            new \DateTime('2011-12-01'),
-            new \DateTime('2011-12-31')
+            new \DateTime($start),
+            new \DateTime($end),
+            $timeZone
         );
 
         // This will normalize the output
@@ -218,6 +222,52 @@ END:VCALENDAR
 ';
 
         $tests[] = array($input, $output);
+
+        // Floating dates and times.
+        $input = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+BEGIN:VEVENT
+UID:bla1
+DTSTART:20141112T195000
+END:VEVENT
+BEGIN:VEVENT
+UID:bla2
+DTSTART;VALUE=DATE:20141112
+END:VEVENT
+BEGIN:VEVENT
+UID:bla3
+DTSTART;VALUE=DATE:20141112
+RRULE:FREQ=DAILY;COUNT=2
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+        $output = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+BEGIN:VEVENT
+UID:bla1
+DTSTART:20141112T225000Z
+END:VEVENT
+BEGIN:VEVENT
+UID:bla2
+DTSTART;VALUE=DATE:20141112
+END:VEVENT
+BEGIN:VEVENT
+UID:bla3
+DTSTART;VALUE=DATE:20141112
+END:VEVENT
+BEGIN:VEVENT
+UID:bla3
+DTSTART;VALUE=DATE:20141113
+RECURRENCE-ID;VALUE=DATE:20141113
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+        $tests[] = array($input, $output, 'America/Argentina/Buenos_Aires', '2014-01-01', '2015-01-01');
+
         return $tests;
 
     }
diff --git a/tests/VObject/Recur/EventIterator/IncorrectExpandTest.php b/tests/VObject/Recur/EventIterator/IncorrectExpandTest.php
index 1410bcc..d6c93d0 100644
--- a/tests/VObject/Recur/EventIterator/IncorrectExpandTest.php
+++ b/tests/VObject/Recur/EventIterator/IncorrectExpandTest.php
@@ -45,7 +45,6 @@ BEGIN:VEVENT
 UID:foo
 DTSTART:20130711T050000Z
 DTEND:20130711T053000Z
-RECURRENCE-ID:20130711T050000Z
 END:VEVENT
 BEGIN:VEVENT
 UID:foo
diff --git a/tests/VObject/Recur/EventIterator/MissingOverriddenTest.php b/tests/VObject/Recur/EventIterator/MissingOverriddenTest.php
index 59a44b2..1de517b 100644
--- a/tests/VObject/Recur/EventIterator/MissingOverriddenTest.php
+++ b/tests/VObject/Recur/EventIterator/MissingOverriddenTest.php
@@ -45,7 +45,6 @@ UID:foo
 DTSTART:20130727T120000Z
 DURATION:PT1H
 SUMMARY:A
-RECURRENCE-ID:20130727T120000Z
 END:VEVENT
 BEGIN:VEVENT
 RECURRENCE-ID:20130728T120000Z

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabre-vobject.git



More information about the Pkg-owncloud-commits mailing list