Description
Symfony version(s) affected
7.1
Description
Hi guys,
The PR #46426 breaks our app because, in our case, DateTime
comes from various sources (php, doctrine, api, external modules). The timezone can either be "UTC" or the server timezone or any "+XX:00" depending on what created the php DateTime
.
PR #46426 requires that the model_timezone
be exactly the same as the timezone of the DateTime
. No such restriction existed in the past.
Having to normalize the timezone of a hundred of DateTime
before passing them to nearly as many FormType
would requires a substantial effort.
Moreover, it is not possible to normalize a RFC date with timezone "+01:00" into the expected model_timezone
"Europe/Paris", for instance.
Can you elaborate on the issues that prompted that PR? In short, is throwing an exception to the face of the user the right approach?
How to reproduce
// This date comes from a RFC date sent in a json payload, csv file, etc
$date = \DateTime::createFromFormat(\DateTimeInterface::ATOM, "2024-10-28T15:00:00+01:00");
$form = $this->createForm(DateTimeType::class, $date, [
'model_timezone' => 'Europe/Paris',
]);
With Symfony 6.4, the log contains this notice:
User Deprecated: Since symfony/form 6.4: Using a "DateTime" instance with a timezone ("+01:00") not matching the configured model timezone "Europe/Paris" is deprecated.
Symfony 7.1 throws a LogicException
.
Possible Solution
No response
Additional Context
No response