Skip to content

Commit

Permalink
Sabre/VObject returns DateTimeImmutable, not a simple DateTime
Browse files Browse the repository at this point in the history
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
  • Loading branch information
georgehrke committed Jun 9, 2017
1 parent e5215ad commit 677267b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
6 changes: 4 additions & 2 deletions apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,13 @@ private function isEventInThePast(VCalendar $vObject) {
$lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp();
} elseif (isset($component->DURATION)) {
$endDate = clone $component->DTSTART->getDateTime();
$endDate->add(DateTimeParser::parse($component->DURATION->getValue()));
// $component->DTEND->getDateTime() returns DateTimeImmutable
$endDate = $endDate->add(DateTimeParser::parse($component->DURATION->getValue()));
$lastOccurrence = $endDate->getTimeStamp();
} elseif (!$component->DTSTART->hasTime()) {
$endDate = clone $component->DTSTART->getDateTime();
$endDate->modify('+1 day');
// $component->DTSTART->getDateTime() returns DateTimeImmutable
$endDate = $endDate->modify('+1 day');
$lastOccurrence = $endDate->getTimeStamp();
} else {
$lastOccurrence = $firstOccurrence;
Expand Down
14 changes: 9 additions & 5 deletions apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ public function testNoMessageSendForPastEvents($veventParams, $expectsMail) {
/** @var Mailer | \PHPUnit_Framework_MockObject_MockObject $mailer */
$mailer = $this->getMockBuilder('OC\Mail\Mailer')->disableOriginalConstructor()->getMock();
$mailer->method('createMessage')->willReturn($mailMessage);
$mailer->expects($this->once())->method('send');
if ($expectsMail) {
$mailer->expects($this->once())->method('send');
} else {
$mailer->expects($this->never())->method('send');
}
/** @var ILogger | \PHPUnit_Framework_MockObject_MockObject $logger */
$logger = $this->getMockBuilder('OC\Log')->disableOriginalConstructor()->getMock();
$timeFactory = $this->getMockBuilder(ITimeFactory::class)->disableOriginalConstructor()->getMock();
Expand All @@ -118,8 +122,8 @@ public function testNoMessageSendForPastEvents($veventParams, $expectsMail) {
$message->method = 'REQUEST';
$message->message = new VCalendar();
$message->message->add('VEVENT', array_merge([
'UID' => $message->uid,
'SEQUENCE' => $message->sequence,
'UID' => 'uid1337',
'SEQUENCE' => 42,
'SUMMARY' => 'Fellowship meeting',
], $veventParams));
$message->sender = 'mailto:gandalf@wiz.ard';
Expand All @@ -139,8 +143,8 @@ public function dataNoMessageSendForPastEvents() {
[['DTSTART' => new \DateTime('2017-01-01 00:00:00')], false],
[['DTSTART' => new \DateTime('2017-01-01 00:00:00'), 'DTEND' => new \DateTime('2017-01-01 00:00:00')], false],
[['DTSTART' => new \DateTime('2017-01-01 00:00:00'), 'DTEND' => new \DateTime('2017-12-31 00:00:00')], true],
[['DTSTART' => new \DateTime('2017-01-01 00:00:00'), 'DURATION' => new \DateInterval('P1D')], false],
[['DTSTART' => new \DateTime('2017-01-01 00:00:00'), 'DURATION' => new \DateInterval('P1Y')], true],
[['DTSTART' => new \DateTime('2017-01-01 00:00:00'), 'DURATION' => 'P1D'], false],
[['DTSTART' => new \DateTime('2017-01-01 00:00:00'), 'DURATION' => 'P52W'], true],
[['DTSTART' => new \DateTime('2017-01-01 00:00:00'), 'DTEND' => new \DateTime('2017-01-01 00:00:00'), 'RRULE' => 'FREQ=WEEKLY'], true],
[['DTSTART' => new \DateTime('2017-01-01 00:00:00'), 'DTEND' => new \DateTime('2017-01-01 00:00:00'), 'RRULE' => 'FREQ=WEEKLY;COUNT=3'], false],
[['DTSTART' => new \DateTime('2017-01-01 00:00:00'), 'DTEND' => new \DateTime('2017-01-01 00:00:00'), 'RRULE' => 'FREQ=WEEKLY;UNTIL=20170301T000000Z'], false],
Expand Down

0 comments on commit 677267b

Please sign in to comment.