fix(rules): datetime class accept invalid dates

This commit is contained in:
Ondrej Vlach 2024-08-07 13:48:07 +02:00
parent 2306622b81
commit 5b43cb6f5a
No known key found for this signature in database
GPG Key ID: 7F141CDACEDEE2DE
3 changed files with 15 additions and 0 deletions

View File

@ -20,5 +20,10 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
if (\DateTimeImmutable::createFromFormat("Y-m-d", $value) === false) {
$fail('validation.format.date_ymd');
}
// DateTime accept dates such as 2021-31-55
$errors = \DateTimeImmutable::getLastErrors();
if (!empty($errors['warning_count'])) {
$fail('validation.date_ymdhi');
}
}
}

View File

@ -20,5 +20,10 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
if (\DateTimeImmutable::createFromFormat("Y-m-d H:i:s", $value . ":00") === false) {
$fail('validation.date_ymdhi');
}
// DateTime accept dates such as 2021-31-55
$errors = \DateTimeImmutable::getLastErrors();
if (!empty($errors['warning_count'])) {
$fail('validation.date_ymdhi');
}
}
}

View File

@ -20,5 +20,10 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
if (\DateTimeImmutable::createFromFormat("Y-m-d H:i:s", $value) === false) {
$fail('validation.date_ymdhis');
}
// DateTime accept dates such as 2021-31-55
$errors = \DateTimeImmutable::getLastErrors();
if (!empty($errors['warning_count'])) {
$fail('validation.date_ymdhi');
}
}
}