From 1467a6b5bb8f7235ed35a2b47b33bd86093288bf Mon Sep 17 00:00:00 2001
From: Jan-Hendrik Willms <tleilax+studip@gmail.com>
Date: Wed, 29 Jun 2022 13:29:28 +0000
Subject: [PATCH] ensure that start is always before end, fixes #651

Merge request studip/studip!737
---
 app/controllers/consultation/admin.php | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/app/controllers/consultation/admin.php b/app/controllers/consultation/admin.php
index 2c48d189402..eca774c4d20 100644
--- a/app/controllers/consultation/admin.php
+++ b/app/controllers/consultation/admin.php
@@ -153,9 +153,16 @@ class Consultation_AdminController extends ConsultationController
         CSRFProtection::verifyUnsafeRequest();
 
         try {
+            $start = $this->getDateAndTime('start');
+            $end = $this->getDateAndTime('end');
+
+            if (date('Hi', $end) <= date('Hi', $start)) {
+                throw new InvalidArgumentException(_('Die Endzeit liegt vor der Startzeit!'));
+            }
+
             $slot_count = ConsultationBlock::countBlocks(
-                $this->getDateAndTime('start'),
-                $this->getDateAndTime('end'),
+                $start,
+                $end,
                 Request::int('day-of-week'),
                 Request::int('interval'),
                 Request::int('duration'),
@@ -169,8 +176,8 @@ class Consultation_AdminController extends ConsultationController
 
             $blocks = ConsultationBlock::generateBlocks(
                 $this->range,
-                $this->getDateAndTime('start'),
-                $this->getDateAndTime('end'),
+                $start,
+                $end,
                 Request::int('day-of-week'),
                 Request::int('interval')
             );
-- 
GitLab