Fixed DateTimeInterface comparaison
Fixed DateTimeInterface comparaison
This commit is contained in:
parent
74a3d0b9c2
commit
9a0bc995bb
@ -72,8 +72,8 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
|
||||
), array_flip($this->fields));
|
||||
}
|
||||
|
||||
if (!$dateTime instanceof \DateTime && !$dateTime instanceof \DateTimeInterface) {
|
||||
throw new TransformationFailedException('Expected a \DateTime or \DateTimeInterface.');
|
||||
if (!$dateTime instanceof \DateTimeInterface) {
|
||||
throw new TransformationFailedException('Expected a \DateTimeInterface.');
|
||||
}
|
||||
|
||||
if ($this->inputTimezone !== $this->outputTimezone) {
|
||||
|
@ -84,8 +84,8 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
|
||||
return '';
|
||||
}
|
||||
|
||||
if (!$dateTime instanceof \DateTime && !$dateTime instanceof \DateTimeInterface) {
|
||||
throw new TransformationFailedException('Expected a \DateTime or \DateTimeInterface.');
|
||||
if (!$dateTime instanceof \DateTimeInterface) {
|
||||
throw new TransformationFailedException('Expected a \DateTimeInterface.');
|
||||
}
|
||||
|
||||
$value = $this->getIntlDateFormatter()->format($dateTime->getTimestamp());
|
||||
|
@ -27,8 +27,8 @@ class DateTimeToRfc3339Transformer extends BaseDateTimeTransformer
|
||||
return '';
|
||||
}
|
||||
|
||||
if (!$dateTime instanceof \DateTime && !$dateTime instanceof \DateTimeInterface) {
|
||||
throw new TransformationFailedException('Expected a \DateTime or \DateTimeInterface.');
|
||||
if (!$dateTime instanceof \DateTimeInterface) {
|
||||
throw new TransformationFailedException('Expected a \DateTimeInterface.');
|
||||
}
|
||||
|
||||
if ($this->inputTimezone !== $this->outputTimezone) {
|
||||
|
@ -99,8 +99,8 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
|
||||
return '';
|
||||
}
|
||||
|
||||
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
||||
throw new TransformationFailedException('Expected a \DateTime or \DateTimeInterface.');
|
||||
if (!$value instanceof \DateTimeInterface) {
|
||||
throw new TransformationFailedException('Expected a \DateTimeInterface.');
|
||||
}
|
||||
|
||||
if (!$value instanceof \DateTimeImmutable) {
|
||||
|
@ -38,8 +38,8 @@ class DateTimeToTimestampTransformer extends BaseDateTimeTransformer
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
||||
throw new TransformationFailedException('Expected a \DateTime or \DateTimeInterface.');
|
||||
if (!$value instanceof \DateTimeInterface) {
|
||||
throw new TransformationFailedException('Expected a \DateTimeInterface.');
|
||||
}
|
||||
|
||||
return $value->getTimestamp();
|
||||
|
@ -51,7 +51,7 @@ class Cookie
|
||||
}
|
||||
|
||||
// convert expiration time to a Unix timestamp
|
||||
if ($expire instanceof \DateTime || $expire instanceof \DateTimeInterface) {
|
||||
if ($expire instanceof \DateTimeInterface) {
|
||||
$expire = $expire->format('U');
|
||||
} elseif (!is_numeric($expire)) {
|
||||
$expire = strtotime($expire);
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface
|
||||
* (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
|
||||
@ -89,7 +89,7 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface
|
||||
*/
|
||||
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')) {
|
||||
|
@ -47,7 +47,7 @@ abstract class AbstractComparisonValidator extends ConstraintValidator
|
||||
// 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);
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ class RangeValidator extends ConstraintValidator
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_numeric($value) && !$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
||||
if (!is_numeric($value) && !$value instanceof \DateTimeInterface) {
|
||||
$this->context->buildViolation($constraint->invalidMessage)
|
||||
->setParameter('{{ value }}', $this->formatValue($value, self::PRETTY_DATE))
|
||||
->setCode(Range::INVALID_CHARACTERS_ERROR)
|
||||
@ -49,7 +49,7 @@ class RangeValidator extends ConstraintValidator
|
||||
// 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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user