Fix TRIGGER properties with absilute date-time values (#3881)

This commit is contained in:
Thomas Bruederli 2014-11-12 11:54:24 +01:00
parent 19674faae8
commit 1c927ee0f4
3 changed files with 21 additions and 14 deletions

View file

@ -522,7 +522,7 @@ class libvcalendar implements Iterator
}
}
$attendee = self::map_keys($params, array_flip($this->attendee_keymap));
$attendee['email'] = preg_replace('/^mailto:/i', '', $value);
$attendee['email'] = preg_replace('!^mailto:!i', '', $value);
if ($prop->name == 'ORGANIZER') {
$attendee['role'] = 'ORGANIZER';
@ -605,11 +605,9 @@ class libvcalendar implements Iterator
switch ($prop->name) {
case 'TRIGGER':
foreach ($prop->parameters() as $pname => $pvalue) {
if ($pname == 'VALUE' && $pvalue == 'DATE-TIME') {
$trigger = '@' . $prop->getDateTime()->format('U');
$alarm['trigger'] = $prop->getDateTime();
}
if ($prop['VALUE'] == 'DATE-TIME') {
$trigger = '@' . $prop->getDateTime()->format('U');
$alarm['trigger'] = $prop->getDateTime();
}
if (!$trigger && ($values = libcalendaring::parse_alaram_value($value))) {
$trigger = $values[2];
@ -638,7 +636,7 @@ class libvcalendar implements Iterator
break;
case 'ATTENDEE':
$alarm['attendees'][] = preg_replace('/^mailto:/i', '', $value);
$alarm['attendees'][] = preg_replace('!^mailto:!i', '', $value);
break;
case 'ATTACH':
@ -710,7 +708,7 @@ class libvcalendar implements Iterator
break;
case 'ORGANIZER':
$this->freebusy['organizer'] = preg_replace('/^mailto:/i', '', $value);
$this->freebusy['organizer'] = preg_replace('!^mailto:!i', '', $value);
break;
case 'FREEBUSY':
@ -835,7 +833,7 @@ class libvcalendar implements Iterator
* @param boolean Set as UTC date
* @param boolean Set as VALUE=DATE property
*/
public function datetime_prop($cal, $name, $dt, $utc = false, $dateonly = null)
public function datetime_prop($cal, $name, $dt, $utc = false, $dateonly = null, $set_type = false)
{
if ($utc) {
$dt->setTimeZone(new \DateTimeZone('UTC'));
@ -845,12 +843,14 @@ class libvcalendar implements Iterator
$is_utc = ($tz = $dt->getTimezone()) && in_array($tz->getName(), array('UTC','GMT','Z'));
}
$is_dateonly = $dateonly === null ? (bool)$dt->_dateonly : (bool)$dateonly;
$vdt = $cal->createProperty($name);
$vdt->setValue($dt);
$vdt = $cal->createProperty($name, $dt, null, $is_dateonly ? 'DATE' : 'DATE-TIME');
if ($is_dateonly) {
$vdt['VALUE'] = 'DATE';
}
else if ($set_type) {
$vdt['VALUE'] = 'DATE-TIME';
}
// register timezone for VTIMEZONE block
if (!$is_utc && !$dateonly && $tz && ($tzname = $tz->getName())) {
@ -1086,7 +1086,7 @@ class libvcalendar implements Iterator
$va = $cal->createComponent('VALARM');
$va->action = $alarm['action'];
if ($alarm['trigger'] instanceof DateTime) {
$va->add($this->datetime_prop($cal, 'TRIGGER', $alarm['trigger'], true));
$va->add($this->datetime_prop($cal, 'TRIGGER', $alarm['trigger'], true, null, true));
}
else {
$va->add('TRIGGER', $alarm['trigger']);
@ -1121,7 +1121,7 @@ class libvcalendar implements Iterator
if ($val[3])
$va->add('TRIGGER', $val[3]);
else if ($val[0] instanceof DateTime)
$va->add($this->datetime_prop($cal, 'TRIGGER', $val[0]));
$va->add($this->datetime_prop($cal, 'TRIGGER', $val[0], true, null, true));
$ve->add($va);
}

View file

@ -218,13 +218,14 @@ class libvcalendar_test extends PHPUnit_Framework_TestCase
$this->assertEquals('DISPLAY', $event['valarms'][0]['action'], "First alarm action");
$this->assertEquals('This is the first event reminder', $event['valarms'][0]['description'], "First alarm text");
$this->assertEquals(2, count($event['valarms']), "List all VALARM blocks");
$this->assertEquals(3, count($event['valarms']), "List all VALARM blocks");
$valarm = $event['valarms'][1];
$this->assertEquals(1, count($valarm['attendees']), "Email alarm attendees");
$this->assertEquals('EMAIL', $valarm['action'], "Second alarm item (action)");
$this->assertEquals('-P1D', $valarm['trigger'], "Second alarm item (trigger)");
$this->assertEquals('This is the reminder message', $valarm['summary'], "Email alarm text");
$this->assertInstanceOf('DateTime', $event['valarms'][2]['trigger'], "Absolute trigger date/time");
// test alarms export
$ics = $ical->export(array($event));
@ -233,6 +234,7 @@ class libvcalendar_test extends PHPUnit_Framework_TestCase
$this->assertContains('DESCRIPTION:This is the first event reminder', $ics, "Alarm description");
$this->assertContains('SUMMARY:This is the reminder message', $ics, "Email alarm summary");
$this->assertContains('ATTENDEE:mailto:reminder-recipient@example.org', $ics, "Email alarm recipient");
$this->assertContains('TRIGGER;VALUE=DATE-TIME:20130812', $ics, "Date-Time trigger");
}
/**

View file

@ -46,6 +46,11 @@ ATTENDEE:mailto:reminder-recipient@example.org
SUMMARY:This is the reminder message
DESCRIPTION:This is the second event reminder
END:VALARM
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:An absolute reminder
TRIGGER;VALUE=DATE-TIME:20130812T160000Z
END:VALARM
END:VEVENT
END:VCALENDAR