Skip to content

[2.7] Fixed DateTimeInterface comparaison #18750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ValueExporter
public function exportValue($value, $depth = 1, $deep = false)
{
if (is_object($value)) {
if ($value instanceof \DateTime || $value instanceof \DateTimeInterface) {
if ($value instanceof \DateTimeInterface) {
return sprintf('Object(%s) - %s', get_class($value), $value->format(\DateTime::ISO8601));
}

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Validator/ConstraintValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protected function formatTypeOf($value)
* (i.e. "false" for false, "1" for 1 etc.). Strings are always wrapped
* in double quotes ("). Objects, arrays and resources are formatted as
* "object", "array" and "resource". If the $format bitmask contains
* the PRETTY_DATE bit, then {@link \DateTime} objects will be formatted
* the PRETTY_DATE bit, then {@link \DateTime} objects will be formatted
* as RFC-3339 dates ("Y-m-d H:i:s").
*
* Be careful when passing message parameters to a constraint violation
Expand All @@ -136,7 +136,7 @@ protected function formatTypeOf($value)
*/
protected function formatValue($value, $format = 0)
{
$isDateTime = $value instanceof \DateTime || $value instanceof \DateTimeInterface;
$isDateTime = $value instanceof \DateTimeInterface;

if (($format & self::PRETTY_DATE) && $isDateTime) {
if (class_exists('IntlDateFormatter')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function validate($value, Constraint $constraint)
// If $value is immutable, convert the compared value to a
// DateTimeImmutable too
$comparedValue = new \DatetimeImmutable($comparedValue);
} elseif ($value instanceof \DateTime || $value instanceof \DateTimeInterface) {
} elseif ($value instanceof \DateTimeInterface) {
// Otherwise use DateTime
$comparedValue = new \DateTime($comparedValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function validate($value, Constraint $constraint)
return;
}

if (!is_numeric($value) && !$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
if (!is_numeric($value) && !$value instanceof \DateTimeInterface) {
if ($this->context instanceof ExecutionContextInterface) {
$this->context->buildViolation($constraint->invalidMessage)
->setParameter('{{ value }}', $this->formatValue($value, self::PRETTY_DATE))
Expand All @@ -57,7 +57,7 @@ public function validate($value, Constraint $constraint)
// This allows to compare with any date/time value supported by
// the DateTime constructor:
// http://php.net/manual/en/datetime.formats.php
if ($value instanceof \DateTime || $value instanceof \DateTimeInterface) {
if ($value instanceof \DateTimeInterface) {
if (is_string($min)) {
$min = new \DateTime($min);
}
Expand Down