[Pkg-owncloud-commits] [php-sabre-vobject] 04/128: Daily recurrance now can be restricted to certain months with BYMONTH

David Prévot taffit at moszumanska.debian.org
Tue May 20 23:10:57 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 7ab0517810ac624b03c54bd19a92865e10c3c20c
Author: Robert Egginton <robert.egginton at c3media.co.uk>
Date:   Mon Nov 11 16:14:18 2013 +0000

    Daily recurrance now can be restricted to certain months with BYMONTH
---
 lib/Sabre/VObject/RecurrenceIterator.php           | 23 +++++++--
 .../RecurrenceIteratorByMonthInDailyTest.php       | 58 ++++++++++++++++++++++
 2 files changed, 77 insertions(+), 4 deletions(-)

diff --git a/lib/Sabre/VObject/RecurrenceIterator.php b/lib/Sabre/VObject/RecurrenceIterator.php
index 9efbc1d..202bf31 100644
--- a/lib/Sabre/VObject/RecurrenceIterator.php
+++ b/lib/Sabre/VObject/RecurrenceIterator.php
@@ -24,6 +24,7 @@ namespace Sabre\VObject;
  *   * FREQ=DAILY
  *     * BYDAY
  *     * BYHOUR
+ *     * BYMONTH
  *   * FREQ=WEEKLY
  *     * BYDAY
  *     * BYHOUR
@@ -693,7 +694,6 @@ class RecurrenceIterator implements \Iterator {
             }
             $currentStamp = $this->currentDate->getTimeStamp();
 
-
             // Checking exception dates
             foreach($this->exceptionDates as $exceptionDate) {
                 if ($this->currentDate == $exceptionDate) {
@@ -771,8 +771,11 @@ class RecurrenceIterator implements \Iterator {
             $recurrenceDays = $this->getDays();
         }
 
-        do {
+        if (isset($this->byMonth)) {
+            $recurrenceMonths = $this->getMonths();
+        }
 
+        do {
             if ($this->byHour) {
                 if ($this->currentDate->format('G') == '23') {
                     // to obey the interval rule
@@ -786,13 +789,16 @@ class RecurrenceIterator implements \Iterator {
 
             }
 
+            // Current month of the year
+            $currentMonth = $this->currentDate->format('n');
+
             // Current day of the week
             $currentDay = $this->currentDate->format('w');
 
             // Current hour of the day
             $currentHour = $this->currentDate->format('G');
 
-        } while (($this->byDay && !in_array($currentDay, $recurrenceDays)) || ($this->byHour && !in_array($currentHour, $recurrenceHours)));
+        } while (($this->byDay && !in_array($currentDay, $recurrenceDays)) || ($this->byHour && !in_array($currentHour, $recurrenceHours)) || ($this->byMonth && !in_array($currentMonth, $recurrenceMonths)));
 
     }
 
@@ -1149,5 +1155,14 @@ class RecurrenceIterator implements \Iterator {
 
         return $recurrenceDays;
     }
-}
 
+    protected function getMonths()
+    {
+        $recurrenceMonths = array();
+        foreach($this->byMonth as $byMonth) {
+            $recurrenceMonths[] = $byMonth;
+        }
+
+        return $recurrenceMonths;
+    }
+}
diff --git a/tests/Sabre/VObject/RecurrenceIteratorByMonthInDailyTest.php b/tests/Sabre/VObject/RecurrenceIteratorByMonthInDailyTest.php
new file mode 100644
index 0000000..9c7d9b0
--- /dev/null
+++ b/tests/Sabre/VObject/RecurrenceIteratorByMonthInDailyTest.php
@@ -0,0 +1,58 @@
+<?php
+
+namespace Sabre\VObject;
+
+use
+    DateTime;
+
+class RecurrenceIteratorByMonthInDailyTest extends \PHPUnit_Framework_TestCase {
+
+    /**
+     * This tests the expansion of dates with DAILY frequency in RRULE with BYMONTH restrictions
+     */
+    function testExpand() {
+
+        $ics = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.4//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+TRANSP:OPAQUE
+DTEND:20070925T183000Z
+UID:uuid
+DTSTAMP:19700101T000000Z
+LOCATION:
+DESCRIPTION:
+STATUS:CONFIRMED
+SEQUENCE:18
+SUMMARY:Stuff
+DTSTART:20070925T160000Z
+CREATED:20071004T144642Z
+RRULE:FREQ=DAILY;BYMONTH=9,10;BYDAY=SU
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+        $vcal = Reader::read($ics);
+        $this->assertInstanceOf('Sabre\\VObject\\Component\\VCalendar', $vcal);
+
+        $vcal->expand(new DateTime('2013-09-28'), new DateTime('2014-09-11'));
+
+        foreach ($vcal->VEVENT as $event) {
+            $dates[] = $event->DTSTART->getValue();
+        }
+
+        $expectedDates = array(
+            "20130929T160000Z",
+            "20131006T160000Z",
+            "20131013T160000Z",
+            "20131020T160000Z",
+            "20131027T160000Z",
+            "20140907T160000Z"
+        );
+
+        $this->assertEquals($expectedDates, $dates, 'Recursed dates are restricted by month');
+    }
+
+}

-- 
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