Use system timezone
authorCyperghost <olaf_schmitz_1@t-online.de>
Mon, 4 Mar 2024 12:37:59 +0000 (13:37 +0100)
committerOlaf Braun <info@braun-development.de>
Thu, 7 Mar 2024 15:37:10 +0000 (16:37 +0100)
wcfsetup/install/files/lib/system/condition/UserRegistrationDateCondition.class.php

index 2be3cfd7cd373dbf485764197f08e804b7620d80..b10a79ff18e2d83565d483fe2aa068e6fe995488 100644 (file)
@@ -51,15 +51,27 @@ class UserRegistrationDateCondition extends AbstractSingleFieldCondition impleme
         }
 
         if (isset($conditionData['registrationDateEnd'])) {
+            $registrationDateEnd = \DateTime::createFromFormat(
+                'Y-m-d',
+                $conditionData['registrationDateEnd'],
+                TIMEZONE
+            );
+            $registrationDateEnd->setTime(23, 59, 59);
             $objectList->getConditionBuilder()->add(
                 'user_table.registrationDate < ?',
-                [\strtotime($conditionData['registrationDateEnd']) + 86400]
+                [$registrationDateEnd->getTimestamp()]
             );
         }
         if (isset($conditionData['registrationDateStart'])) {
+            $registrationDateStart = \DateTime::createFromFormat(
+                'Y-m-d',
+                $conditionData['registrationDateStart'],
+                TIMEZONE
+            );
+            $registrationDateStart->setTime(0, 0, 0);
             $objectList->getConditionBuilder()->add(
                 'user_table.registrationDate >= ?',
-                [\strtotime($conditionData['registrationDateStart'])]
+                [$registrationDateStart->getTimestamp()]
             );
         }
     }
@@ -70,15 +82,21 @@ class UserRegistrationDateCondition extends AbstractSingleFieldCondition impleme
     public function checkUser(Condition $condition, User $user)
     {
         /** @noinspection PhpUndefinedFieldInspection */
-        $registrationDateStart = $condition->registrationDateStart;
-        if ($registrationDateStart !== null && $user->registrationDate < \strtotime($registrationDateStart)) {
-            return false;
+        $registrationDateStart = \DateTime::createFromFormat('Y-m-d', $condition->registrationDateStart, TIMEZONE);
+        if ($registrationDateStart !== false) {
+            $registrationDateStart->setTime(0, 0, 0);
+            if ($user->registrationDate < $registrationDateStart->getTimestamp()) {
+                return false;
+            }
         }
 
         /** @noinspection PhpUndefinedFieldInspection */
-        $registrationDateEnd = $condition->registrationDateEnd;
-        if ($registrationDateEnd !== null && $user->registrationDate >= \strtotime($registrationDateEnd) + 86400) {
-            return false;
+        $registrationDateEnd = \DateTime::createFromFormat('Y-m-d', $condition->registrationDateEnd, TIMEZONE);
+        if ($registrationDateEnd !== false) {
+            $registrationDateEnd->setTime(23, 59, 59);
+            if ($user->registrationDate >= $registrationDateEnd->getTimestamp()) {
+                return false;
+            }
         }
 
         return true;
@@ -166,7 +184,7 @@ HTML;
     {
         $registrationDateEnd = $registrationDateStart = null;
         if (\strlen($this->registrationDateStart)) {
-            $registrationDateStart = @\strtotime($this->registrationDateStart);
+            $registrationDateStart = \DateTime::createFromFormat('Y-m-d', $this->registrationDateStart, TIMEZONE);
             if ($registrationDateStart === false) {
                 $this->errorMessage = 'wcf.condition.timestamp.error.invalidStart';
 
@@ -174,7 +192,7 @@ HTML;
             }
         }
         if (\strlen($this->registrationDateEnd)) {
-            $registrationDateEnd = @\strtotime($this->registrationDateEnd);
+            $registrationDateEnd = \DateTime::createFromFormat('Y-m-d', $this->registrationDateEnd, TIMEZONE);
             if ($registrationDateEnd === false) {
                 $this->errorMessage = 'wcf.condition.timestamp.error.invalidEnd';