Bläddra i källkod

Cnage Validator - date

Add error: The :alias field contains the time before the start of the Unix epoch.
Visman 1 år sedan
förälder
incheckning
304a1d720f
3 ändrade filer med 19 tillägg och 8 borttagningar
  1. 13 8
      app/Core/Validator.php
  2. 3 0
      app/lang/en/validator.po
  3. 3 0
      app/lang/ru/validator.po

+ 13 - 8
app/Core/Validator.php

@@ -956,16 +956,21 @@ class Validator
     protected function vDate(Validator $v, mixed $value): ?string
     {
         if ($this->noValue($value)) {
-            $value = null;
-        } elseif (
-            ! \is_string($value)
-            || false === \strtotime("{$value} UTC")
-        ) {
-            $v->addError('The :alias does not contain a date');
+            return null;
+        }
 
-            $value = \is_scalar($value) ? (string) $value : null;
+        if (\is_string($value)) {
+            $timestamp = \strtotime("{$value} UTC");
+        } else {
+            $timestamp = false;
         }
 
-        return $value;
+        if (false === $timestamp) {
+            $v->addError('The :alias does not contain a date');
+        } elseif ($timestamp < 0) {
+            $v->addError('The :alias contains time before start of Unix');
+        }
+
+        return \is_scalar($value) ? (string) $value : null;
     }
 }

+ 3 - 0
app/lang/en/validator.po

@@ -218,3 +218,6 @@ msgstr "Invalid passphrase."
 
 msgid "Javascript disabled or bot"
 msgstr "Your browser most likely has javascript disabled or you are a robot :)"
+
+msgid "The :alias contains time before start of Unix"
+msgstr "The :alias field contains the time before the start of the Unix epoch."

+ 3 - 0
app/lang/ru/validator.po

@@ -218,3 +218,6 @@ msgstr "Неверная кодовая фраза."
 
 msgid "Javascript disabled or bot"
 msgstr "В вашем браузере, вероятнее всего, выключен javascript или вы робот :)"
+
+msgid "The :alias contains time before start of Unix"
+msgstr "Поле :alias содержит время предшествующее началу эпохи Unix."