From 0b0a50a8e30e1aaaa6ab052ac4c0df18b5d36b73 Mon Sep 17 00:00:00 2001
From: Peter Thienel <thienel@data-quest.de>
Date: Thu, 21 Mar 2024 18:26:37 +0100
Subject: [PATCH] special treatment for all-day events to display them
 correctly in fullcalendar, re #3875

---
 lib/classes/calendar/EventData.class.php      | 30 ++++++++++++++-----
 .../calendar/CalendarDateAssignment.class.php |  3 +-
 2 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/lib/classes/calendar/EventData.class.php b/lib/classes/calendar/EventData.class.php
index 82afe6f3b77..95e89b0ec6a 100644
--- a/lib/classes/calendar/EventData.class.php
+++ b/lib/classes/calendar/EventData.class.php
@@ -69,15 +69,29 @@ class EventData
 
     public function toFullcalendarEvent()
     {
-        //Note: The timezone must not be transmitted or
-        //the events may be shifted when there is a timezone
-        //or daylight saving time difference between the server
-        //and the client!
-        return [
+        // Note: The timezone must not be transmitted or
+        // the events may be shifted when there is a timezone
+        // or daylight saving time difference between the server
+        // and the client!
+        // To display all-day events correctly in fullcalendar
+        // reduce the start and end to date without time and add one day
+        // to the end date...
+        if ($this->all_day) {
+            $fc_date = [
+                'allDay' => true,
+                'start'  => $this->begin->format('Y-m-d'),
+                'end'    => $this->end->modify('+1 day')->format('Y-m-d')
+            ];
+        } else {
+            $fc_date = [
+                'allDay' => false,
+                'start'  => $this->begin->format('Y-m-d\TH:i:s'),
+                'end'    => $this->end->format('Y-m-d\TH:i:s')
+            ];
+        }
+
+        return $fc_date + [
             'resourceId' => $this->range_id,
-            'start' => $this->begin->format('Y-m-d\TH:i:s'),
-            'end' => $this->end->format('Y-m-d\TH:i:s'),
-            'allDay' => $this->all_day,
             'title' => $this->title,
             'classNames' => $this->event_classes,
             'textColor' => $this->text_colour,
diff --git a/lib/models/calendar/CalendarDateAssignment.class.php b/lib/models/calendar/CalendarDateAssignment.class.php
index 101cb9642b5..4e084c2436e 100644
--- a/lib/models/calendar/CalendarDateAssignment.class.php
+++ b/lib/models/calendar/CalendarDateAssignment.class.php
@@ -507,8 +507,7 @@ class CalendarDateAssignment extends SimpleORMap implements Event
             return false;
         }
         $end = $this->getEnd();
-        return ($end->format('Ymd') === $begin->format('Ymd')
-            && $end->format('His') === '235959');
+        return $end->format('His') === '235959';
     }
 
     public function isWritable(string $user_id): bool
-- 
GitLab