Skip to content

Commit 93edad4

Browse files
davidespagnolihenriquemoody
authored andcommitted
Reset missing date information in CanValidateDateTime
Missing date information are now reset to 0 (1970-01-01T00:00:00), because otherwise they are taken from current date/time, so: `Respect\Validation\Validator::date("m")->isValid('06')` is not valid on 31st of every month.
1 parent 6537256 commit 93edad4

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

library/Helpers/CanValidateDateTime.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private function isDateTime(string $format, string $value): bool
4444

4545
if ($this->isDateFormat($format)) {
4646
$formattedDate = DateTime::createFromFormat(
47-
$format,
47+
'!' . $format,
4848
$value,
4949
new DateTimeZone(date_default_timezone_get())
5050
);

tests/unit/Helpers/CanValidateDateTimeTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public function shouldFindWhenValueIsNotDateTime(string $format, string $value):
4848
public static function providerForValidDateTime(): array
4949
{
5050
return [
51+
'overflow days' => ['m-Y', '02-2025'],
5152
['Y-m-d', '2009-09-09'],
5253
['Y-m-d', '2020-02-29'],
5354
['Ymd', '20090909'],

0 commit comments

Comments
 (0)