Skip to content

Commit 7e92213

Browse files
committed
[Serializer] Add PRESERVE_CONTEXT_TIMEZONE_KEY to DateTimeNormalizer
Adds DateTimeNormalizer::PRESERVE_CONTEXT_TIMEZONE_KEY to the `DateTimeNormalizer` section
1 parent 6c3a18d commit 7e92213

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Diff for: serializer.rst

+11-1
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,12 @@ normalizers (in order of priority):
13441344
`RFC 3339`_ format. Use ``DateTimeNormalizer::FORMAT_KEY`` and
13451345
``DateTimeNormalizer::TIMEZONE_KEY`` to change the format.
13461346

1347+
To always create :phpclass:`DateTime` and :phpclass:`DateTimeImmutable`
1348+
with the timezone specified in the context, set the
1349+
``DateTimeNormalizer::PRESERVE_CONTEXT_TIMEZONE_KEY`` context option to
1350+
``true``. This will preserve the timezone of the context and ignores any
1351+
timezone from the input.
1352+
13471353
To convert the objects to integers or floats, set the serializer
13481354
context option ``DateTimeNormalizer::CAST_KEY`` to ``int`` or
13491355
``float``.
@@ -1352,6 +1358,10 @@ normalizers (in order of priority):
13521358

13531359
The ``DateTimeNormalizer::CAST_KEY`` context option was introduced in Symfony 7.1.
13541360

1361+
.. versionadded:: 7.3
1362+
1363+
The ``DateTimeNormalizer::PRESERVE_CONTEXT_TIMEZONE_KEY`` context option was introduced in Symfony 7.3.
1364+
13551365
:class:`Symfony\\Component\\Serializer\\Normalizer\\ConstraintViolationListNormalizer`
13561366
This normalizer converts objects that implement
13571367
:class:`Symfony\\Component\\Validator\\ConstraintViolationListInterface`
@@ -1436,7 +1446,7 @@ normalizers (in order of priority):
14361446
14371447
$propertyInfo = new PropertyInfoExtractor([], [new PhpDocExtractor(), new ReflectionExtractor()]);
14381448
$normalizers = [new ObjectNormalizer(new ClassMetadataFactory(new AttributeLoader()), null, null, $propertyInfo), new ArrayDenormalizer()];
1439-
1449+
14401450
$this->serializer = new Serializer($normalizers, [new JsonEncoder()]);
14411451
14421452
:class:`Symfony\\Component\\Serializer\\Normalizer\\ObjectNormalizer`

0 commit comments

Comments
 (0)