Improve error handling of invalid dates
authorMarcel Werk <burntime@woltlab.com>
Wed, 21 Aug 2024 09:49:44 +0000 (11:49 +0200)
committerMarcel Werk <burntime@woltlab.com>
Wed, 21 Aug 2024 09:49:44 +0000 (11:49 +0200)
wcfsetup/install/files/lib/system/search/SearchHandler.class.php

index 1640eeba3220e8cd3d212810501a5298cda106b3..bf52e0f6559f42e10b1411de750b0806badb775b 100644 (file)
@@ -148,28 +148,30 @@ final class SearchHandler
 
     private function buildDateCondition(): void
     {
+        $startDate = 0;
         if (!empty($this->parameters['startDate'])) {
             $startDateTime = \DateTime::createFromFormat(
                 "Y-m-d",
                 $this->parameters['startDate'],
                 WCF::getUser()->getTimezone()
             );
-            $startDateTime->setTime(0, 0, 0);
-            $startDate = $startDateTime->getTimestamp();
-        } else {
-            $startDate = 0;
+            if ($startDateTime !== false) {
+                $startDateTime->setTime(0, 0, 0);
+                $startDate = $startDateTime->getTimestamp();
+            }
         }
 
+        $endDate = 0;
         if (!empty($this->parameters['endDate'])) {
             $endDateTime = \DateTime::createFromFormat(
                 "Y-m-d",
                 $this->parameters['endDate'],
                 WCF::getUser()->getTimezone()
             );
-            $endDateTime->setTime(23, 59, 59);
-            $endDate = $endDateTime->getTimestamp();
-        } else {
-            $endDate = 0;
+            if ($endDateTime !== false) {
+                $endDateTime->setTime(23, 59, 59);
+                $endDate = $endDateTime->getTimestamp();
+            }
         }
 
         if ($startDate && $endDate) {