From 74cbbbbd2e00c29f50b7ba0b1c6ad534f5c689d6 Mon Sep 17 00:00:00 2001
From: Moritz Strohm <strohm@data-quest.de>
Date: Mon, 25 Mar 2024 08:44:43 +0000
Subject: [PATCH] calendar/date/add: remove one second for dates that
 fullcalendar marked as all-day, fixes #3878

Closes #3878

Merge request studip/studip!2733


(cherry picked from commit 8b18b2d101f4f514e55ba100112f62eb8ac514df)

b46ffe23 calendar/date/add: remove one second for dates that fullcalendar marked as all-day
18217903 Apply 1 suggestion(s) to 1 file(s)
---
 app/controllers/calendar/date.php | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/app/controllers/calendar/date.php b/app/controllers/calendar/date.php
index fea47d2ba88..e4030a5a423 100644
--- a/app/controllers/calendar/date.php
+++ b/app/controllers/calendar/date.php
@@ -356,8 +356,16 @@ class Calendar_DateController extends AuthenticatedController
         }
 
         $this->all_day_event = false;
-        if ($mode === 'add' && Request::get('all_day') === '1') {
+        if ($mode === 'add' && Request::bool('all_day')) {
             $this->all_day_event = true;
+            //Check for a fullcalendar all-day event ending. In that case, remove one second to have an all-day event
+            //that abides to the Stud.IP rules.
+            $end = new DateTime();
+            $end->setTimestamp($this->date->end);
+            if ($end->format('His') === '000000') {
+                $end = $end->sub(new DateInterval('PT1S'));
+            }
+            $this->date->end = $end->getTimestamp();
         } else {
             $begin = new DateTime();
             $begin->setTimestamp(intval($this->date->begin));
-- 
GitLab