Skip to content

Commit 38c6d67

Browse files
committed
Update datetime rule
1 parent 47c9ef3 commit 38c6d67

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/Validator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,10 @@ public static function datetime(
408408
return false;
409409
}
410410
$lastErrors = \DateTime::getLastErrors();
411-
return $lastErrors
412-
&& $lastErrors['warning_count'] === 0
411+
if ($lastErrors === false) {
412+
return true;
413+
}
414+
return $lastErrors['warning_count'] === 0
413415
&& $lastErrors['error_count'] === 0;
414416
}
415417

tests/ValidatorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ public function testDatetime() : void
176176
self::assertTrue(Validator::datetime('year', $this->array, 'Y'));
177177
self::assertFalse(Validator::datetime('alpha', $this->array));
178178
self::assertFalse(Validator::datetime('unknown', $this->array));
179+
self::assertFalse(Validator::datetime('foo', [
180+
'foo' => '2022-02-29 25:10:10',
181+
]));
179182
}
180183

181184
public function testEquals() : void

0 commit comments

Comments
 (0)