Skip to content

Commit

Permalink
ITip\Broker: handle timezones in replies to exception events
Browse files Browse the repository at this point in the history
Co-authored-by: Luc DUZAN <[email protected]>
  • Loading branch information
gharlan and Luc DUZAN committed May 8, 2024
1 parent caa7af8 commit 2a65337
Show file tree
Hide file tree
Showing 2 changed files with 192 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/ITip/Broker.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ protected function processMessageReply(Message $itipMessage, ?VCalendar $existin

// Finding all the instances the attendee replied to.
foreach ($itipMessage->message->VEVENT as $vevent) {
$recurId = isset($vevent->{'RECURRENCE-ID'}) ? $vevent->{'RECURRENCE-ID'}->getValue() : 'master';
$recurId = isset($vevent->{'RECURRENCE-ID'}) ? $vevent->{'RECURRENCE-ID'}->getDateTime()->getTimestamp() : 'master';
$attendee = $vevent->ATTENDEE;
$instances[$recurId] = $attendee['PARTSTAT']->getValue();
if (isset($vevent->{'REQUEST-STATUS'})) {
Expand All @@ -346,7 +346,7 @@ protected function processMessageReply(Message $itipMessage, ?VCalendar $existin
// all the instances where we have a reply for.
$masterObject = null;
foreach ($existingObject->VEVENT as $vevent) {
$recurId = isset($vevent->{'RECURRENCE-ID'}) ? $vevent->{'RECURRENCE-ID'}->getValue() : 'master';
$recurId = isset($vevent->{'RECURRENCE-ID'}) ? $vevent->{'RECURRENCE-ID'}->getDateTime()->getTimestamp() : 'master';
if ('master' === $recurId) {
$masterObject = $vevent;
}
Expand Down Expand Up @@ -393,7 +393,7 @@ protected function processMessageReply(Message $itipMessage, ?VCalendar $existin
$newObject = $recurrenceIterator->getEventObject();
$recurrenceIterator->next();

if (isset($newObject->{'RECURRENCE-ID'}) && $newObject->{'RECURRENCE-ID'}->getValue() === $recurId) {
if (isset($newObject->{'RECURRENCE-ID'}) && $newObject->{'RECURRENCE-ID'}->getDateTime()->getTimestamp() === $recurId) {
$found = true;
}
--$iterations;
Expand Down
189 changes: 189 additions & 0 deletions tests/VObject/ITip/BrokerProcessReplyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,75 @@ public function testReplyPartyCrasher(): void
$this->process($itip, $old, $expected);
}

public function testReplyExistingExceptionRecurrenceIdInUTC(): void
{
// This is a reply to 1 instance of a recurring event. This should
// automatically create an exception.
$itip = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
METHOD:REPLY
BEGIN:VEVENT
ATTENDEE;PARTSTAT=ACCEPTED:mailto:[email protected]
ORGANIZER:mailto:[email protected]
SEQUENCE:2
RECURRENCE-ID:20140725T040000Z
UID:foobar
END:VEVENT
END:VCALENDAR
ICS;

$old = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
SEQUENCE:2
UID:foobar
RRULE:FREQ=DAILY
DTSTART;TZID=America/Toronto:20140724T000000
DTEND;TZID=America/Toronto:20140724T010000
ATTENDEE:mailto:[email protected]
ORGANIZER:mailto:[email protected]
END:VEVENT
BEGIN:VEVENT
SEQUENCE:2
UID:foobar
DTSTART;TZID=America/Toronto:20140725T000000
DTEND;TZID=America/Toronto:20140725T010000
ATTENDEE:mailto:[email protected]
ORGANIZER:mailto:[email protected]
RECURRENCE-ID;TZID=America/Toronto:20140725T000000
END:VEVENT
END:VCALENDAR
ICS;

$expected = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
SEQUENCE:2
UID:foobar
RRULE:FREQ=DAILY
DTSTART;TZID=America/Toronto:20140724T000000
DTEND;TZID=America/Toronto:20140724T010000
ATTENDEE:mailto:[email protected]
ORGANIZER:mailto:[email protected]
END:VEVENT
BEGIN:VEVENT
SEQUENCE:2
UID:foobar
DTSTART;TZID=America/Toronto:20140725T000000
DTEND;TZID=America/Toronto:20140725T010000
ATTENDEE;PARTSTAT=ACCEPTED;SCHEDULE-STATUS=2.0:mailto:[email protected]
ORGANIZER:mailto:[email protected]
RECURRENCE-ID;TZID=America/Toronto:20140725T000000
END:VEVENT
END:VCALENDAR
ICS;

$this->process($itip, $old, $expected);
}

public function testReplyNewException(): void
{
// This is a reply to 1 instance of a recurring event. This should
Expand Down Expand Up @@ -373,6 +442,126 @@ public function testReplyNewExceptionTz(): void
$this->process($itip, $old, $expected);
}

public function testReplyNewExceptionRecurrenceIdInDifferentTz(): void
{
// This is a reply to 1 instance of a recurring event. This should
// automatically create an exception.
$itip = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
METHOD:REPLY
BEGIN:VEVENT
ATTENDEE;PARTSTAT=ACCEPTED:mailto:[email protected]
ORGANIZER:mailto:[email protected]
SEQUENCE:2
RECURRENCE-ID;TZID=Asia/Ho_Chi_Minh:20140725T110000
UID:foobar
END:VEVENT
END:VCALENDAR
ICS;

$old = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
SEQUENCE:2
UID:foobar
RRULE:FREQ=DAILY
DTSTART;TZID=America/Toronto:20140724T000000
DTEND;TZID=America/Toronto:20140724T010000
ATTENDEE:mailto:[email protected]
ORGANIZER:mailto:[email protected]
END:VEVENT
END:VCALENDAR
ICS;

$expected = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
SEQUENCE:2
UID:foobar
RRULE:FREQ=DAILY
DTSTART;TZID=America/Toronto:20140724T000000
DTEND;TZID=America/Toronto:20140724T010000
ATTENDEE:mailto:[email protected]
ORGANIZER:mailto:[email protected]
END:VEVENT
BEGIN:VEVENT
SEQUENCE:2
UID:foobar
DTSTART;TZID=America/Toronto:20140725T000000
DTEND;TZID=America/Toronto:20140725T010000
ATTENDEE;PARTSTAT=ACCEPTED:mailto:[email protected]
ORGANIZER:mailto:[email protected]
RECURRENCE-ID;TZID=America/Toronto:20140725T000000
END:VEVENT
END:VCALENDAR
ICS;

$this->process($itip, $old, $expected);
}

public function testReplyNewExceptionRecurrenceIdInUTC(): void
{
// This is a reply to 1 instance of a recurring event. This should
// automatically create an exception.
$itip = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
METHOD:REPLY
BEGIN:VEVENT
ATTENDEE;PARTSTAT=ACCEPTED:mailto:[email protected]
ORGANIZER:mailto:[email protected]
SEQUENCE:2
RECURRENCE-ID:20140725T040000Z
UID:foobar
END:VEVENT
END:VCALENDAR
ICS;

$old = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
SEQUENCE:2
UID:foobar
RRULE:FREQ=DAILY
DTSTART;TZID=America/Toronto:20140724T000000
DTEND;TZID=America/Toronto:20140724T010000
ATTENDEE:mailto:[email protected]
ORGANIZER:mailto:[email protected]
END:VEVENT
END:VCALENDAR
ICS;

$expected = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
SEQUENCE:2
UID:foobar
RRULE:FREQ=DAILY
DTSTART;TZID=America/Toronto:20140724T000000
DTEND;TZID=America/Toronto:20140724T010000
ATTENDEE:mailto:[email protected]
ORGANIZER:mailto:[email protected]
END:VEVENT
BEGIN:VEVENT
SEQUENCE:2
UID:foobar
DTSTART;TZID=America/Toronto:20140725T000000
DTEND;TZID=America/Toronto:20140725T010000
ATTENDEE;PARTSTAT=ACCEPTED:mailto:[email protected]
ORGANIZER:mailto:[email protected]
RECURRENCE-ID;TZID=America/Toronto:20140725T000000
END:VEVENT
END:VCALENDAR
ICS;

$this->process($itip, $old, $expected);
}

public function testReplyPartyCrashCreateException(): void
{
// IN this test there's a recurring event that has an exception. The
Expand Down

0 comments on commit 2a65337

Please sign in to comment.