diff --git a/src/Symfony/Component/Validator/Constraints/DateValidator.php b/src/Symfony/Component/Validator/Constraints/DateValidator.php index 0c6bf5fb0f50f..3013cd4a6a36a 100644 --- a/src/Symfony/Component/Validator/Constraints/DateValidator.php +++ b/src/Symfony/Component/Validator/Constraints/DateValidator.php @@ -25,6 +25,10 @@ public function isValid($value, Constraint $constraint) return true; } + if ($value instanceof \DateTime) { + return true; + } + if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString()'))) { throw new UnexpectedTypeException($value, 'string'); } diff --git a/tests/Symfony/Tests/Component/Validator/Constraints/DateValidatorTest.php b/tests/Symfony/Tests/Component/Validator/Constraints/DateValidatorTest.php index fd42c5906b601..b0325b4e550d5 100644 --- a/tests/Symfony/Tests/Component/Validator/Constraints/DateValidatorTest.php +++ b/tests/Symfony/Tests/Component/Validator/Constraints/DateValidatorTest.php @@ -54,6 +54,7 @@ public function getValidDates() array('2010-01-01'), array('1955-12-12'), array('2030-05-31'), + array(new \DateTime('2010-01-01')), ); }
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: