Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Serializer] Add PRESERVE_CONTEXT_TIMEZONE_KEY to DateTimeNormalizer #20860

Open
wants to merge 1 commit into
base: 7.3
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion serializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,12 @@ normalizers (in order of priority):
`RFC 3339`_ format. Use ``DateTimeNormalizer::FORMAT_KEY`` and
``DateTimeNormalizer::TIMEZONE_KEY`` to change the format.

To always create :phpclass:`DateTime` and :phpclass:`DateTimeImmutable`
with the timezone specified in the context, set the
``DateTimeNormalizer::PRESERVE_CONTEXT_TIMEZONE_KEY`` context option to
``true``. This will preserve the timezone of the context and ignores any
timezone from the input.

To convert the objects to integers or floats, set the serializer
context option ``DateTimeNormalizer::CAST_KEY`` to ``int`` or
``float``.
Expand All @@ -1352,6 +1358,10 @@ normalizers (in order of priority):

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

.. versionadded:: 7.3

The ``DateTimeNormalizer::PRESERVE_CONTEXT_TIMEZONE_KEY`` context option was introduced in Symfony 7.3.

:class:`Symfony\\Component\\Serializer\\Normalizer\\ConstraintViolationListNormalizer`
This normalizer converts objects that implement
:class:`Symfony\\Component\\Validator\\ConstraintViolationListInterface`
Expand Down Expand Up @@ -1436,7 +1446,7 @@ normalizers (in order of priority):

$propertyInfo = new PropertyInfoExtractor([], [new PhpDocExtractor(), new ReflectionExtractor()]);
$normalizers = [new ObjectNormalizer(new ClassMetadataFactory(new AttributeLoader()), null, null, $propertyInfo), new ArrayDenormalizer()];

$this->serializer = new Serializer($normalizers, [new JsonEncoder()]);

:class:`Symfony\\Component\\Serializer\\Normalizer\\ObjectNormalizer`
Expand Down