Skip to content

Commit

Permalink
Merge pull request #48723 from nextcloud/fix/caldav/event-reader-dura…
Browse files Browse the repository at this point in the history
…tion

fix(caldav): duration handling in the event reader class
  • Loading branch information
st3iny authored Nov 4, 2024
2 parents 9014962 + cbcc8fc commit d3cecf5
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions apps/dav/lib/CalDAV/EventReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace OCA\DAV\CalDAV;

use DateTime;
use DateTimeImmutable;
use DateTimeInterface;
use DateTimeZone;
use InvalidArgumentException;
Expand Down Expand Up @@ -109,7 +110,7 @@ public function __construct(VCalendar|VEvent|array|string $input, ?string $uid =
unset($events[$key]);
}
}

// No base event was found. CalDAV does allow cases where only
// overridden instances are stored.
//
Expand Down Expand Up @@ -173,15 +174,17 @@ public function __construct(VCalendar|VEvent|array|string $input, ?string $uid =
// evaluate if duration exists
// extract duration and calculate end date
elseif (isset($this->baseEvent->DURATION)) {
$this->baseEventDuration = $this->baseEvent->DURATION->getDateInterval();
$this->baseEventEndDate = ((clone $this->baseEventStartDate)->add($this->baseEventDuration));
$this->baseEventEndDate = DateTimeImmutable::createFromInterface($this->baseEventStartDate)
->add($this->baseEvent->DURATION->getDateInterval());
$this->baseEventDuration = $this->baseEventEndDate->getTimestamp() - $this->baseEventStartDate->getTimestamp();
}
// evaluate if start date is floating
// set duration to 24 hours and calculate the end date
// according to the rfc any event without a end date or duration is a complete day
elseif ($this->baseEventStartDateFloating == true) {
$this->baseEventDuration = 86400;
$this->baseEventEndDate = ((clone $this->baseEventStartDate)->add($this->baseEventDuration));
$this->baseEventEndDate = DateTimeImmutable::createFromInterface($this->baseEventStartDate)
->setTimestamp($this->baseEventStartDate->getTimestamp() + $this->baseEventDuration);
}
// otherwise, set duration to zero this should never happen
else {
Expand Down Expand Up @@ -220,7 +223,7 @@ public function __construct(VCalendar|VEvent|array|string $input, ?string $uid =
foreach ($events as $vevent) {
$this->recurrenceModified[$vevent->{'RECURRENCE-ID'}->getDateTime($this->baseEventStartTimeZone)->getTimeStamp()] = $vevent;
}

$this->recurrenceCurrentDate = clone $this->baseEventStartDate;
}

Expand Down Expand Up @@ -375,7 +378,7 @@ public function recurringConcludes(): bool {
* @return int|null
*/
public function recurringConcludesAfter(): ?int {

// construct count place holder
$count = 0;
// retrieve and add RRULE iterations count
Expand Down

0 comments on commit d3cecf5

Please sign in to comment.