Fix TRIGGER properties with absilute date-time values (#3881)
This commit is contained in:
parent
19674faae8
commit
1c927ee0f4
3 changed files with 21 additions and 14 deletions
|
@ -522,7 +522,7 @@ class libvcalendar implements Iterator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$attendee = self::map_keys($params, array_flip($this->attendee_keymap));
|
$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') {
|
if ($prop->name == 'ORGANIZER') {
|
||||||
$attendee['role'] = 'ORGANIZER';
|
$attendee['role'] = 'ORGANIZER';
|
||||||
|
@ -605,11 +605,9 @@ class libvcalendar implements Iterator
|
||||||
|
|
||||||
switch ($prop->name) {
|
switch ($prop->name) {
|
||||||
case 'TRIGGER':
|
case 'TRIGGER':
|
||||||
foreach ($prop->parameters() as $pname => $pvalue) {
|
if ($prop['VALUE'] == 'DATE-TIME') {
|
||||||
if ($pname == 'VALUE' && $pvalue == 'DATE-TIME') {
|
$trigger = '@' . $prop->getDateTime()->format('U');
|
||||||
$trigger = '@' . $prop->getDateTime()->format('U');
|
$alarm['trigger'] = $prop->getDateTime();
|
||||||
$alarm['trigger'] = $prop->getDateTime();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!$trigger && ($values = libcalendaring::parse_alaram_value($value))) {
|
if (!$trigger && ($values = libcalendaring::parse_alaram_value($value))) {
|
||||||
$trigger = $values[2];
|
$trigger = $values[2];
|
||||||
|
@ -638,7 +636,7 @@ class libvcalendar implements Iterator
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'ATTENDEE':
|
case 'ATTENDEE':
|
||||||
$alarm['attendees'][] = preg_replace('/^mailto:/i', '', $value);
|
$alarm['attendees'][] = preg_replace('!^mailto:!i', '', $value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'ATTACH':
|
case 'ATTACH':
|
||||||
|
@ -710,7 +708,7 @@ class libvcalendar implements Iterator
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'ORGANIZER':
|
case 'ORGANIZER':
|
||||||
$this->freebusy['organizer'] = preg_replace('/^mailto:/i', '', $value);
|
$this->freebusy['organizer'] = preg_replace('!^mailto:!i', '', $value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'FREEBUSY':
|
case 'FREEBUSY':
|
||||||
|
@ -835,7 +833,7 @@ class libvcalendar implements Iterator
|
||||||
* @param boolean Set as UTC date
|
* @param boolean Set as UTC date
|
||||||
* @param boolean Set as VALUE=DATE property
|
* @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) {
|
if ($utc) {
|
||||||
$dt->setTimeZone(new \DateTimeZone('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_utc = ($tz = $dt->getTimezone()) && in_array($tz->getName(), array('UTC','GMT','Z'));
|
||||||
}
|
}
|
||||||
$is_dateonly = $dateonly === null ? (bool)$dt->_dateonly : (bool)$dateonly;
|
$is_dateonly = $dateonly === null ? (bool)$dt->_dateonly : (bool)$dateonly;
|
||||||
$vdt = $cal->createProperty($name);
|
$vdt = $cal->createProperty($name, $dt, null, $is_dateonly ? 'DATE' : 'DATE-TIME');
|
||||||
$vdt->setValue($dt);
|
|
||||||
|
|
||||||
if ($is_dateonly) {
|
if ($is_dateonly) {
|
||||||
$vdt['VALUE'] = 'DATE';
|
$vdt['VALUE'] = 'DATE';
|
||||||
}
|
}
|
||||||
|
else if ($set_type) {
|
||||||
|
$vdt['VALUE'] = 'DATE-TIME';
|
||||||
|
}
|
||||||
|
|
||||||
// register timezone for VTIMEZONE block
|
// register timezone for VTIMEZONE block
|
||||||
if (!$is_utc && !$dateonly && $tz && ($tzname = $tz->getName())) {
|
if (!$is_utc && !$dateonly && $tz && ($tzname = $tz->getName())) {
|
||||||
|
@ -1086,7 +1086,7 @@ class libvcalendar implements Iterator
|
||||||
$va = $cal->createComponent('VALARM');
|
$va = $cal->createComponent('VALARM');
|
||||||
$va->action = $alarm['action'];
|
$va->action = $alarm['action'];
|
||||||
if ($alarm['trigger'] instanceof DateTime) {
|
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 {
|
else {
|
||||||
$va->add('TRIGGER', $alarm['trigger']);
|
$va->add('TRIGGER', $alarm['trigger']);
|
||||||
|
@ -1121,7 +1121,7 @@ class libvcalendar implements Iterator
|
||||||
if ($val[3])
|
if ($val[3])
|
||||||
$va->add('TRIGGER', $val[3]);
|
$va->add('TRIGGER', $val[3]);
|
||||||
else if ($val[0] instanceof DateTime)
|
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);
|
$ve->add($va);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -218,13 +218,14 @@ class libvcalendar_test extends PHPUnit_Framework_TestCase
|
||||||
$this->assertEquals('DISPLAY', $event['valarms'][0]['action'], "First alarm action");
|
$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('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];
|
$valarm = $event['valarms'][1];
|
||||||
$this->assertEquals(1, count($valarm['attendees']), "Email alarm attendees");
|
$this->assertEquals(1, count($valarm['attendees']), "Email alarm attendees");
|
||||||
$this->assertEquals('EMAIL', $valarm['action'], "Second alarm item (action)");
|
$this->assertEquals('EMAIL', $valarm['action'], "Second alarm item (action)");
|
||||||
$this->assertEquals('-P1D', $valarm['trigger'], "Second alarm item (trigger)");
|
$this->assertEquals('-P1D', $valarm['trigger'], "Second alarm item (trigger)");
|
||||||
$this->assertEquals('This is the reminder message', $valarm['summary'], "Email alarm text");
|
$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
|
// test alarms export
|
||||||
$ics = $ical->export(array($event));
|
$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('DESCRIPTION:This is the first event reminder', $ics, "Alarm description");
|
||||||
$this->assertContains('SUMMARY:This is the reminder message', $ics, "Email alarm summary");
|
$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('ATTENDEE:mailto:reminder-recipient@example.org', $ics, "Email alarm recipient");
|
||||||
|
$this->assertContains('TRIGGER;VALUE=DATE-TIME:20130812', $ics, "Date-Time trigger");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -46,6 +46,11 @@ ATTENDEE:mailto:reminder-recipient@example.org
|
||||||
SUMMARY:This is the reminder message
|
SUMMARY:This is the reminder message
|
||||||
DESCRIPTION:This is the second event reminder
|
DESCRIPTION:This is the second event reminder
|
||||||
END:VALARM
|
END:VALARM
|
||||||
|
BEGIN:VALARM
|
||||||
|
ACTION:DISPLAY
|
||||||
|
DESCRIPTION:An absolute reminder
|
||||||
|
TRIGGER;VALUE=DATE-TIME:20130812T160000Z
|
||||||
|
END:VALARM
|
||||||
END:VEVENT
|
END:VEVENT
|
||||||
|
|
||||||
END:VCALENDAR
|
END:VCALENDAR
|
||||||
|
|
Loading…
Add table
Reference in a new issue