Skip to content

Commit

Permalink
[jan] Export VTIMEZONE components only once per TZID (Bug #12988).
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed May 14, 2014
1 parent 5c9a5f8 commit d6fd510
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 3 deletions.
10 changes: 9 additions & 1 deletion framework/Icalendar/lib/Horde/Icalendar.php
Expand Up @@ -481,6 +481,7 @@ public function clear()
$this->_attributes = $this->_components = array();
}

public function toString() { return $this->exportvCalendar(); }
/**
* Export as vCalendar format.
*
Expand Down Expand Up @@ -1130,8 +1131,15 @@ protected function _exportvData($base = 'VCALENDAR')
}
}

$tzs = array();
foreach ($this->_components as $component) {
$result .= $component->exportvCalendar();
if (!($component instanceof Horde_Icalendar_Vtimezone) ||
!isset($tzs[$component->getAttribute('TZID')])) {
$result .= $component->exportvCalendar();
if ($component instanceof Horde_Icalendar_Vtimezone) {
$tzs[$component->getAttribute('TZID')] = true;
}
}
}

return $result . 'END:' . $base . $this->_newline;
Expand Down
4 changes: 2 additions & 2 deletions framework/Icalendar/package.xml
Expand Up @@ -35,7 +35,7 @@
</stability>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
* [jan] Export VTIMEZONE components only once per TZID (Bug #12988).
</notes>
<contents>
<dir baseinstalldir="/" name="/">
Expand Down Expand Up @@ -1124,7 +1124,7 @@ Lots of improvements, bugfixes and support for more fields and members of the iC
<date>2013-07-16</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
* [jan] Export VTIMEZONE components only once per TZID (Bug #12988).
</notes>
</release>
</changelog>
Expand Down
105 changes: 105 additions & 0 deletions framework/Icalendar/test/Horde/Icalendar/ExportTest.php
Expand Up @@ -208,6 +208,111 @@ public function testTimezone()
DTSTART;TZID=Europe/Berlin:20100101T020000
END:VEVENT
END:VCALENDAR
',
$ical->exportVCalendar()
);

$ical = new Horde_Icalendar();
$tz = $ical->parsevCalendar(
'BEGIN:VCALENDAR
BEGIN:VTIMEZONE
TZID:Europe/Berlin
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
DTSTART:19800406T010000
RRULE:FREQ=YEARLY;BYMONTH=4;BYDAY=1SU;UNTIL=19800406T00000Z
TZNAME:CEST
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
DTSTART:19800928T010000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=9;UNTIL=19950923T23000Z
TZNAME:CE-T
END:STANDARD
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
DTSTART:19810329T010000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
TZNAME:CEST
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
DTSTART:19961027T010000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
TZNAME:CE-T
END:STANDARD
END:VTIMEZONE
END:VCALENDAR
'
);
$tz = $ical->getComponent(0);
$ical = new Horde_Icalendar();
$ical->addComponent($tz);
$event = Horde_Icalendar::newComponent('vevent', $ical);
$event->setAttribute('UID', 'uid');
$event->setAttribute('DTSTAMP', $date);
$date->setTimezone('Europe/Berlin');
$event->setAttribute('DTSTART', $date, array('TZID' => 'Europe/Berlin'));
$ical->addComponent($event);
$ical->addComponent($tz);
$event = Horde_Icalendar::newComponent('vevent', $ical);
$event->setAttribute('UID', 'uid2');
$event->setAttribute('DTSTAMP', $date);
$date->setTimezone('Europe/Berlin');
$start = clone $date;
$start->mday++;
$event->setAttribute('DTSTART', $start, array('TZID' => 'Europe/Berlin'));
$ical->addComponent($event);
$this->assertEquals(
'BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//The Horde Project//Horde iCalendar Library//EN
BEGIN:VTIMEZONE
TZID:Europe/Berlin
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
DTSTART:19800406T010000
RRULE:FREQ=YEARLY;BYMONTH=4;BYDAY=1SU;UNTIL=19800406T00000Z
TZNAME:CEST
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
DTSTART:19800928T010000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=9;UNTIL=19950923T23000Z
TZNAME:CE-T
END:STANDARD
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
DTSTART:19810329T010000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
TZNAME:CEST
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
DTSTART:19961027T010000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
TZNAME:CE-T
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
UID:uid
DTSTAMP:20100101T010000Z
DTSTART;TZID=Europe/Berlin:20100101T020000
END:VEVENT
BEGIN:VEVENT
UID:uid2
DTSTAMP:20100101T010000Z
DTSTART;TZID=Europe/Berlin:20100102T020000
END:VEVENT
END:VCALENDAR
',
$ical->exportVCalendar()
);
Expand Down

0 comments on commit d6fd510

Please sign in to comment.