Closed
Description
Symfony version(s) affected: 4.3.5
Description
The validator update in 4.3.5 passes the timezone from the DateTime object to IntlDateFormatter which breaks when using zulu timestamps (YYYY-MM-DDTHH:MM:SSZ).
How to reproduce
Extend constraint validator and attempt to validate a zulu timestamp as PRETTY_DATE:
<?php
use \DateTime;
use \Symfony\Component\Validator\Constraint;
use \Symfony\Component\Validator\ConstraintValidator;
class TestValidator extends ConstraintValidator
{
public function __construct()
{
$dateTime = new DateTime('2022-12-12T08:30:42Z');
// This will throw a fatal error
$this->formatValue($dateTime, ConstraintValidator::PRETTY_DATE);
}
public function validate($value, Constraint $constraint)
{
}
}
Possible Solution
Check the validity of the timezone before passing it to IntlDateFormatter.
Additional context
Error returned:
IntlException : datefmt_create: time zone id 'Z' extracted from ext/date DateTimeZone not recognized: U_ILLEGAL_ARGUMENT_ERROR