Skip to content

Conversation

@frankdekker
Copy link

@frankdekker frankdekker commented Apr 5, 2025

Adds DateTimeNormalizer::PRESERVE_CONTEXT_TIMEZONE_KEY to the DateTimeNormalizer section

Documentation for:

@carsonbot carsonbot added this to the 7.3 milestone Apr 5, 2025
@OskarStark OskarStark added the Waiting Code Merge Docs for features pending to be merged label Apr 6, 2025
@carsonbot carsonbot modified the milestones: 7.3, next Apr 6, 2025
@OskarStark OskarStark changed the title [Serializer] Add PRESERVE_CONTEXT_TIMEZONE_KEY to DateTimeNormalizer [Serializer] Add PRESERVE_CONTEXT_TIMEZONE_KEY to DateTimeNormalizer Jun 19, 2025
Adds DateTimeNormalizer::PRESERVE_CONTEXT_TIMEZONE_KEY to the `DateTimeNormalizer` section
nicolas-grekas added a commit to symfony/symfony that referenced this pull request Nov 1, 2025
…izer` during denormalization (frankdekker)

This PR was squashed before being merged into the 7.4 branch.

Discussion
----------

[Serializer] Allow forcing timezone in `DateTimeNormalizer` during denormalization

| Q             | A
| ------------- | ---
| Branch?       | 7.4
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Issues        | Fix #59807
| License       | MIT

By default the `DateTimeNormalizer` will denormalize timestamps and date strings that include a timezone to `DateTime` objects with respective timezone UTC or the timezone from the date string. Even with the context key `TIMEZONE_KEY` set, the timezone from the input superceeds the context timezone.

This PR allows to set `PRESERVE_CONTEXT_TIMEZONE_KEY` context to `true` (default: `false`), which in combination with `TIMEZONE_KEY` will set the Timezone of the denormalized DateTimes to the given timezone. The timezone from the input will be overwritten.

### Documentation
symfony/symfony-docs#20860

Commits
-------

bd1a4d0 [Serializer] Allow forcing timezone in `DateTimeNormalizer` during denormalization
Change version to 7.4

Co-authored-by: Matty Driessen <mdriessen@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Serializer Status: Needs Review Waiting Code Merge Docs for features pending to be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants