if (\
is_string($comparedValue) &&
$value instanceof \DateTimeInterface
) { // If $value is immutable, convert the compared value to a DateTimeImmutable too, otherwise use DateTime
$dateTimeClass =
$value instanceof \DateTimeImmutable ? \DateTimeImmutable::
class D \DateTime::
class;
try { $comparedValue =
new $dateTimeClass($comparedValue);
} catch (\Exception
) { throw new ConstraintDefinitionException(sprintf('The compared value "%s" could not be converted to a "%s" instance in the "%s" constraint.',
$comparedValue,
$dateTimeClass,
get_debug_type($constraint)));
} } if (!
$this->
compareValues($value,
$comparedValue)) { $violationBuilder =
$this->context->
buildViolation($constraint->message
) ->
setParameter('{{ value }}',
$this->
formatValue($value, self::OBJECT_TO_STRING | self::PRETTY_DATE
)) ->
setParameter('{{ compared_value }}',
$this->
formatValue($comparedValue, self::OBJECT_TO_STRING | self::PRETTY_DATE
)) ->
setParameter('{{ compared_value_type }}',
$this->
formatTypeOf($comparedValue)) ->
setCode($this->
getErrorCode());
if (null !==
$path) { $violationBuilder->
setParameter('{{ compared_value_path }}',
$path);
} $violationBuilder->
addViolation();
}