Skip to content

[WCM] Serializer DateTimeNormalizer #11497

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

Closed
wants to merge 9 commits into from
28 changes: 28 additions & 0 deletions components/serializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,34 @@ There are several types of normalizers available:
:phpclass:`DateTime` and :phpclass:`DateTimeImmutable`) into strings.
By default it uses the RFC3339_ format.

The context for the
:class:`Symfony\\Component\\Serializer\\Normalizer\\DateTimeNormalizer` allows
setting of:

+ ``FORMAT_KEY`` specifies the format of the datetime string to be returned by
the normalizer, and the format of the datetime string supplied to the
denormalizer.
+ ``TIMEZONE_KEY`` the timezone that the normalizer and denormalizer use to return
the datetime result. **NB:** Legacy operation may vary for the denormalizer as
detailed below.
+ ``PRESERVE_CONTEXT_TIMEZONE`` is a boolean flag to allow use of **legacy**
denormalizer functionality.

**Legacy**

PHP :phpclass:`DateTimeInterface` constructor and createFromFormat() method will
return a result with a timezone that may not be the default timezone if the time
parameter has timezone information embedded (e.g. 2010-01-28T15:00:00+02:00) or the
time parameter is a UNIX timestamp (e.g. @946684800).

To use default PHP (legacy) behavior in the denormalizer, set
``PRESERVE_CONTEXT_TIMEZONE`` to ``false``.

``.. deprecated: 4.2``

Not setting the ``PRESERVE_CONTEXT_TIMEZONE`` is deprecated since Symfony 4.2. This
flag and legacy behavior will be retired in Symfony 5.0.

:class:`Symfony\\Component\\Serializer\\Normalizer\\DataUriNormalizer`
This normalizer converts :phpclass:`SplFileInfo` objects into a data URI
string (``data:...``) such that files can be embedded into serialized data.
Expand Down