From 154145c51b08185bbb318be9abefc2386187cd9c Mon Sep 17 00:00:00 2001 From: Frank Dekker Date: Sat, 5 Apr 2025 13:54:55 +0200 Subject: [PATCH 1/3] [Serializer] Add PRESERVE_CONTEXT_TIMEZONE_KEY to DateTimeNormalizer Adds DateTimeNormalizer::PRESERVE_CONTEXT_TIMEZONE_KEY to the `DateTimeNormalizer` section --- serializer.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/serializer.rst b/serializer.rst index 083a2420015..8520233f86e 100644 --- a/serializer.rst +++ b/serializer.rst @@ -1373,6 +1373,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``. @@ -1381,6 +1387,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` From d52d7081836e29fa9d8f37f3af3dbf85fddf32c8 Mon Sep 17 00:00:00 2001 From: Frank Dekker Date: Sat, 1 Nov 2025 10:55:58 +0100 Subject: [PATCH 2/3] [Serializer] Add PRESERVE_CONTEXT_TIMEZONE_KEY to DateTimeNormalizer - Updated docs to updated const --- serializer.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/serializer.rst b/serializer.rst index 8520233f86e..8551bace7dd 100644 --- a/serializer.rst +++ b/serializer.rst @@ -1375,8 +1375,8 @@ normalizers (in order of priority): 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 + ``DateTimeNormalizer::FORCE_TIMEZONE_KEY`` context option to + ``true``. This will force the timezone of the context and ignores any timezone from the input. To convert the objects to integers or floats, set the serializer @@ -1387,9 +1387,9 @@ normalizers (in order of priority): The ``DateTimeNormalizer::CAST_KEY`` context option was introduced in Symfony 7.1. - .. versionadded:: 7.3 + .. versionadded:: 7.4 - The ``DateTimeNormalizer::PRESERVE_CONTEXT_TIMEZONE_KEY`` context option was introduced in Symfony 7.3. + The ``DateTimeNormalizer::FORCE_TIMEZONE_KEY`` context option was introduced in Symfony 7.3. :class:`Symfony\\Component\\Serializer\\Normalizer\\ConstraintViolationListNormalizer` This normalizer converts objects that implement From 5d6c96c4bc01dc4bac380c0febfa86ee97f515e4 Mon Sep 17 00:00:00 2001 From: Frank Dekker Date: Sat, 1 Nov 2025 15:14:02 +0100 Subject: [PATCH 3/3] [Serializer] Add PRESERVE_CONTEXT_TIMEZONE_KEY to DateTimeNormalizer Change version to 7.4 Co-authored-by: Matty Driessen --- serializer.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serializer.rst b/serializer.rst index 8551bace7dd..7abcb1ddb26 100644 --- a/serializer.rst +++ b/serializer.rst @@ -1389,7 +1389,7 @@ normalizers (in order of priority): .. versionadded:: 7.4 - The ``DateTimeNormalizer::FORCE_TIMEZONE_KEY`` context option was introduced in Symfony 7.3. + The ``DateTimeNormalizer::FORCE_TIMEZONE_KEY`` context option was introduced in Symfony 7.4. :class:`Symfony\\Component\\Serializer\\Normalizer\\ConstraintViolationListNormalizer` This normalizer converts objects that implement