Browse Source

Fix ISO8601 validation from Validator

Johan Meiring 6 years ago
parent
commit
6ef2be7410
2 changed files with 7 additions and 1 deletions
  1. 3 0
      src/Validation/Validation.php
  2. 4 1
      tests/TestCase/Validation/ValidatorTest.php

+ 3 - 0
src/Validation/Validation.php

@@ -541,6 +541,9 @@ class Validation
         if (is_object($check)) {
             return false;
         }
+        if (is_array($dateFormat) && count($dateFormat) === 1) {
+            $dateFormat = reset($dateFormat);
+        }
         if ($dateFormat === static::DATETIME_ISO8601 && !static::iso8601($check)) {
             return false;
         }

+ 4 - 1
tests/TestCase/Validation/ValidatorTest.php

@@ -2489,11 +2489,14 @@ class ValidatorTest extends TestCase
      *
      * @return void
      */
-    public function testDateTime()
+    public function testDateTime(): void
     {
         $validator = new Validator();
         $this->assertProxyMethod($validator, 'dateTime', ['ymd'], [['ymd']], 'datetime');
         $this->assertNotEmpty($validator->validate(['username' => 'not a date']));
+
+        $validator = (new Validator())->dateTime('thedate', ['iso8601']);
+        $this->assertEmpty($validator->validate(['thedate' => '2020-05-01T12:34:56Z']));
     }
 
     /**