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));
|
), array_flip($this->fields));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$dateTime instanceof \DateTime && !$dateTime instanceof \DateTimeInterface) {
|
if (!$dateTime instanceof \DateTimeInterface) {
|
||||||
throw new TransformationFailedException('Expected a \DateTime or \DateTimeInterface.');
|
throw new TransformationFailedException('Expected a \DateTimeInterface.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->inputTimezone !== $this->outputTimezone) {
|
if ($this->inputTimezone !== $this->outputTimezone) {
|
||||||
|
@ -84,8 +84,8 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$dateTime instanceof \DateTime && !$dateTime instanceof \DateTimeInterface) {
|
if (!$dateTime instanceof \DateTimeInterface) {
|
||||||
throw new TransformationFailedException('Expected a \DateTime or \DateTimeInterface.');
|
throw new TransformationFailedException('Expected a \DateTimeInterface.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$value = $this->getIntlDateFormatter()->format($dateTime->getTimestamp());
|
$value = $this->getIntlDateFormatter()->format($dateTime->getTimestamp());
|
||||||
|
@ -27,8 +27,8 @@ class DateTimeToRfc3339Transformer extends BaseDateTimeTransformer
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$dateTime instanceof \DateTime && !$dateTime instanceof \DateTimeInterface) {
|
if (!$dateTime instanceof \DateTimeInterface) {
|
||||||
throw new TransformationFailedException('Expected a \DateTime or \DateTimeInterface.');
|
throw new TransformationFailedException('Expected a \DateTimeInterface.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->inputTimezone !== $this->outputTimezone) {
|
if ($this->inputTimezone !== $this->outputTimezone) {
|
||||||
|
@ -99,8 +99,8 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
if (!$value instanceof \DateTimeInterface) {
|
||||||
throw new TransformationFailedException('Expected a \DateTime or \DateTimeInterface.');
|
throw new TransformationFailedException('Expected a \DateTimeInterface.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$value instanceof \DateTimeImmutable) {
|
if (!$value instanceof \DateTimeImmutable) {
|
||||||
|
@ -38,8 +38,8 @@ class DateTimeToTimestampTransformer extends BaseDateTimeTransformer
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
if (!$value instanceof \DateTimeInterface) {
|
||||||
throw new TransformationFailedException('Expected a \DateTime or \DateTimeInterface.');
|
throw new TransformationFailedException('Expected a \DateTimeInterface.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $value->getTimestamp();
|
return $value->getTimestamp();
|
||||||
|
@ -51,7 +51,7 @@ class Cookie
|
|||||||
}
|
}
|
||||||
|
|
||||||
// convert expiration time to a Unix timestamp
|
// convert expiration time to a Unix timestamp
|
||||||
if ($expire instanceof \DateTime || $expire instanceof \DateTimeInterface) {
|
if ($expire instanceof \DateTimeInterface) {
|
||||||
$expire = $expire->format('U');
|
$expire = $expire->format('U');
|
||||||
} elseif (!is_numeric($expire)) {
|
} elseif (!is_numeric($expire)) {
|
||||||
$expire = strtotime($expire);
|
$expire = strtotime($expire);
|
||||||
|
@ -28,7 +28,7 @@ class ValueExporter
|
|||||||
public function exportValue($value, $depth = 1, $deep = false)
|
public function exportValue($value, $depth = 1, $deep = false)
|
||||||
{
|
{
|
||||||
if (is_object($value)) {
|
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));
|
return sprintf('Object(%s) - %s', get_class($value), $value->format(\DateTime::ISO8601));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface
|
|||||||
*/
|
*/
|
||||||
protected function formatValue($value, $format = 0)
|
protected function formatValue($value, $format = 0)
|
||||||
{
|
{
|
||||||
$isDateTime = $value instanceof \DateTime || $value instanceof \DateTimeInterface;
|
$isDateTime = $value instanceof \DateTimeInterface;
|
||||||
|
|
||||||
if (($format & self::PRETTY_DATE) && $isDateTime) {
|
if (($format & self::PRETTY_DATE) && $isDateTime) {
|
||||||
if (class_exists('IntlDateFormatter')) {
|
if (class_exists('IntlDateFormatter')) {
|
||||||
|
@ -47,7 +47,7 @@ abstract class AbstractComparisonValidator extends ConstraintValidator
|
|||||||
// If $value is immutable, convert the compared value to a
|
// If $value is immutable, convert the compared value to a
|
||||||
// DateTimeImmutable too
|
// DateTimeImmutable too
|
||||||
$comparedValue = new \DatetimeImmutable($comparedValue);
|
$comparedValue = new \DatetimeImmutable($comparedValue);
|
||||||
} elseif ($value instanceof \DateTime || $value instanceof \DateTimeInterface) {
|
} elseif ($value instanceof \DateTimeInterface) {
|
||||||
// Otherwise use DateTime
|
// Otherwise use DateTime
|
||||||
$comparedValue = new \DateTime($comparedValue);
|
$comparedValue = new \DateTime($comparedValue);
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class RangeValidator extends ConstraintValidator
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_numeric($value) && !$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
if (!is_numeric($value) && !$value instanceof \DateTimeInterface) {
|
||||||
$this->context->buildViolation($constraint->invalidMessage)
|
$this->context->buildViolation($constraint->invalidMessage)
|
||||||
->setParameter('{{ value }}', $this->formatValue($value, self::PRETTY_DATE))
|
->setParameter('{{ value }}', $this->formatValue($value, self::PRETTY_DATE))
|
||||||
->setCode(Range::INVALID_CHARACTERS_ERROR)
|
->setCode(Range::INVALID_CHARACTERS_ERROR)
|
||||||
@ -49,7 +49,7 @@ class RangeValidator extends ConstraintValidator
|
|||||||
// This allows to compare with any date/time value supported by
|
// This allows to compare with any date/time value supported by
|
||||||
// the DateTime constructor:
|
// the DateTime constructor:
|
||||||
// http://php.net/manual/en/datetime.formats.php
|
// http://php.net/manual/en/datetime.formats.php
|
||||||
if ($value instanceof \DateTime || $value instanceof \DateTimeInterface) {
|
if ($value instanceof \DateTimeInterface) {
|
||||||
if (is_string($min)) {
|
if (is_string($min)) {
|
||||||
$min = new \DateTime($min);
|
$min = new \DateTime($min);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user