0009856: ics import: recurring events one day earlier
authorPhilipp Schüle <p.schuele@metaways.de>
Fri, 9 May 2014 12:37:40 +0000 (14:37 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Mon, 12 May 2014 13:12:39 +0000 (15:12 +0200)
* converts dtstart to originator TZ when normalizing rrule
* adds ics import test case with first of May

https://forge.tine20.org/mantisbt/view.php?id=9856

Change-Id: If8beacb6e658f44ebf556c1df402a9e372b042d9
Reviewed-on: http://gerrit.tine20.com/customers/617
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Calendar/Import/ICalTest.php
tests/tine20/Calendar/Import/files/ni-zsk.ics [new file with mode: 0644]
tine20/Calendar/Model/Rrule.php

index f4e1592..72ed88d 100644 (file)
@@ -4,21 +4,19 @@
  * 
  * @package     Calendar
  * @license     http://www.gnu.org/licenses/agpl.html
- * @copyright   Copyright (c) 2010 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright   Copyright (c) 2010-2014 Metaways Infosystems GmbH (http://www.metaways.de)
  * @author      Cornelius Weiss <c.weiss@metaways.de>
  * 
  */
 
 /**
- * Test helper
- */
-require_once dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
-
-/**
  * Test class for Calendar_Import_ICal
  */
 class Calendar_Import_ICalTest extends Calendar_TestCase
 {
+    /**
+     * testImportSimpleFromString
+     */
     public function testImportSimpleFromString()
     {
         $importer = new Calendar_Import_Ical(array(
@@ -176,4 +174,33 @@ class Calendar_Import_ICalTest extends Calendar_TestCase
         $failMessage = print_r($output, TRUE);
         $this->_checkImport($failMessage);
     }
+    
+    /**
+     * testImportRruleNormalize
+     * 
+     * @see 0009856: ics import: recurring events one day earlier
+     */
+    public function testImportRruleNormalize()
+    {
+        $importer = new Calendar_Import_Ical(array(
+            'importContainerId' => $this->_testCalendar->getId(),
+        ));
+        
+        $importer->importFile(dirname(__FILE__) . '/files/ni-zsk.ics');
+        
+        // fetch first of may in 2014
+        $from = new Tinebase_DateTime('2014-04-23 22:00:00');
+        $until = new Tinebase_DateTime('2014-05-23 22:00:00');
+        $events = Calendar_Controller_Event::getInstance()->search(new Calendar_Model_EventFilter(array(
+            array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_testCalendar->getId()),
+            array('field' => 'period', 'operator' => 'within', 'value' => array(
+                'from'  => $from->toString(),
+                'until' => $until->toString()
+            )),
+        )), NULL);
+        Calendar_Model_Rrule::mergeRecurrenceSet($events, $from, $until);
+        $firstOfMay2014 = $events[1];
+        
+        $this->assertEquals('2014-04-30 22:00:00', $firstOfMay2014->dtstart);
+    }
 }
diff --git a/tests/tine20/Calendar/Import/files/ni-zsk.ics b/tests/tine20/Calendar/Import/files/ni-zsk.ics
new file mode 100644 (file)
index 0000000..6c06c55
--- /dev/null
@@ -0,0 +1,35 @@
+BEGIN:VCALENDAR\r
+VERSION:2.0\r
+METHOD:PUBLISH\r
+X-WR-CALNAME:Feiertage\r
+PRODID:-//s3net//iFeiertage.de 4.0.1//EN\r
+X-WR-CALDESC:Feier- und Festtage Niedersachsen\r
+X-APPLE-CALENDAR-COLOR:#B027AE\r
+X-WR-TIMEZONE:Europe/Berlin\r
+CALSCALE:GREGORIAN\r
+BEGIN:VTIMEZONE\r
+TZID:Europe/Berlin\r
+BEGIN:DAYLIGHT\r
+TZOFFSETFROM:+0100\r
+TZOFFSETTO:+0200\r
+DTSTART:19810329T020000\r
+RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU\r
+TZNAME:CEST\r
+END:DAYLIGHT\r
+BEGIN:STANDARD\r
+TZOFFSETFROM:+0200\r
+TZOFFSETTO:+0100\r
+DTSTART:19961027T030000\r
+RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU\r
+TZNAME:CET\r
+END:STANDARD\r
+END:VTIMEZONE\r
+BEGIN:VEVENT\r
+UID:DE-IF-0501\r
+DTSTART;VALUE=DATE:20100501\r
+DTEND;VALUE=DATE:20100502\r
+RRULE:FREQ=YEARLY;INTERVAL=1\r
+SUMMARY:Tag der Arbeit\r
+DTSTAMP:20100101T000000Z\r
+END:VEVENT\r
+END:VCALENDAR\r
index af5155b..651cdd4 100644 (file)
@@ -273,7 +273,14 @@ class Calendar_Model_Rrule extends Tinebase_Record_Abstract
      * 
      * @param Calendar_Model_Event $event
      */
-    public function normalize(Calendar_Model_Event $event) {
+    public function normalize(Calendar_Model_Event $event)
+    {
+        // set originators TZ to get correct byday/bymonth/bymonthday rrules
+        $originatorDtStart = clone($event->dtstart);
+        if (! empty($event->originator_tz)) {
+            $originatorDtStart->setTimezone($event->originator_tz);
+        }
+        
         switch ($this->freq) {
             case self::FREQ_WEEKLY:
                 if (! $this->wkst ) {
@@ -281,22 +288,22 @@ class Calendar_Model_Rrule extends Tinebase_Record_Abstract
                 }
             
                 if (! $this->byday) {
-                    $this->byday = array_search($event->dtstart->format('w'), self::$WEEKDAY_DIGIT_MAP);
+                    $this->byday = array_search($originatorDtStart->format('w'), self::$WEEKDAY_DIGIT_MAP);
                 }
                 break;
             
             case self::FREQ_MONTHLY:
                 if (! $this->byday && ! $this->bymonthday) {
-                    $this->bymonthday = $event->dtstart->format('j');
+                    $this->bymonthday = $originatorDtStart->format('j');
                 }
                 break;
                 
             case self::FREQ_YEARLY:
                 if (! $this->byday && ! $this->bymonthday) {
-                    $this->bymonthday = $event->dtstart->format('j');
+                    $this->bymonthday = $originatorDtStart->format('j');
                 }
                 if (! $this->bymonth) {
-                    $this->bymonth = $event->dtstart->format('n');
+                    $this->bymonth = $originatorDtStart->format('n');
                 }
                 break;
             default: