diff --git a/lib/Controller/OptionController.php b/lib/Controller/OptionController.php index 8df257e67..345fc2364 100644 --- a/lib/Controller/OptionController.php +++ b/lib/Controller/OptionController.php @@ -128,10 +128,13 @@ class OptionController extends Controller { */ public function findCalendarEvents($optionId): DataResponse { return $this->response(function () use ($optionId) { + $option = $this->optionService->get($optionId); $searchFrom = new DateTime(); - $searchFrom = $searchFrom->setTimestamp($this->optionService->get($optionId)->getTimestamp())->sub(new DateInterval('PT1H')); - $searchTo = clone $searchFrom; - $searchTo = $searchTo->add(new DateInterval('PT3H')); + $searchTo = new DateTime(); + // Search calendar entries which end inside one hour before option start time + $searchFrom = $searchFrom->setTimestamp($option->getTimestamp())->sub(new DateInterval('PT1H')); + // Search calendar entries which start inside one hour after option end time + $searchTo = $searchTo->setTimestamp($option->getTimestamp() + $option->getDuration())->add(new DateInterval('PT1H')); $events = $this->calendarService->getEvents($searchFrom, $searchTo); return ['events' => $events]; }); diff --git a/lib/Service/CalendarService.php b/lib/Service/CalendarService.php index 1d44048cd..e5bcd5dd0 100644 --- a/lib/Service/CalendarService.php +++ b/lib/Service/CalendarService.php @@ -73,7 +73,7 @@ class CalendarService { // since we get back recurring events of other days, just make sure this event // matches the search pattern - // TODO: identify possible time zone issues, whan handling all day events + // TODO: identify possible time zone issues, when handling all day events if (($from->getTimestamp() < $calendarEvent->getEnd()) && ($to->getTimestamp() > $calendarEvent->getStart())) { array_push($events, $calendarEvent);