8000 deprecate using the TimeType with date objects with not-matching time… · symfony/symfony@97a0564 · GitHub
[go: up one dir, main page]

Skip to content

Commit 97a0564

Browse files
committed
deprecate using the TimeType with date objects with not-matching timezones
1 parent 4dde161 commit 97a0564

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

UPGRADE-6.2.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
UPGRADE FROM 6.1 to 6.2
2+
=======================
3+
4+
Form
5+
----
6+
7+
* Deprecate using `DateTime` or `DateTimeImmutable` model data with a different timezone than configured with the
8+
`model_timezone` option.

src/Symfony/Component/Form/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGELOG
22
=========
33

4+
6.2
5+
---
6+
7+
* Deprecate using `DateTime` or `DateTimeImmutable` model data with a different timezone than configured with the
8+
`model_timezone` option.
9+
410
6.1
511
---
612

src/Symfony/Component/Form/Extension/Core/Type/TimeType.php

+14
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,20 @@ public function buildForm(FormBuilderInterface $builder, array $options)
210210
new DateTimeToArrayTransformer($options['model_timezone'], $options['model_timezone'], $parts, 'text' === $options['widget'], $options['reference_date'])
211211
));
212212
}
213+
214+
if (\in_array($options['input'], ['datetime', 'datetime_immutable'], true) && null !== $options['model_timezone']) {
215+
$builder->addEventListener(FormEvents::PRE_SET_DATA, static function (FormEvent $event) use ($options): void {
216+
$date = $event->getData();
217+
218+
if (!$date instanceof \DateTimeInterface) {
219+
return;
220+
}
221+
222+
if ($date->getTimezone()->getName() !== $options['model_timezone']) {
223+
trigger_deprecation('symfony/form', '6.2', 'Different model timezone');
224+
}
225+
});
226+
}
213227
}
214228

215229
/**

0 commit comments

Comments
 (0)
0