Skip to content
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