-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Allow custom timezone in DateTimeNormalizer
during denormalization
#60153
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
base: 7.3
Are you sure you want to change the base?
Conversation
Add PRESERVE_CONTEXT_TIMEZONE_KEY and adjust DateTime object during denormalization
Add test coverage
Update changelog.md
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
Updated codequality failures
Possibility of lowering complexity: There are currently 2 similar blocks of code for I was hesistant to do this immediately because i have no idea why there is different error handling for the context $dateTimeFormat. |
DateTimeNormalizer
during denormalization
src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php
Outdated
Show resolved
Hide resolved
Fix review remarks
Add `withPreserveContextTimezone` to `DateTimeNormalizerContextBuilder`
By default the
DateTimeNormalizer
will denormalize timestamps and date strings that include a timezone toDateTime
objects with respective timezone UTC or the timezone from the date string. Even with the context keyTIMEZONE_KEY
set, the timezone from the input superceeds the context timezone.This PR allows to set
PRESERVE_CONTEXT_TIMEZONE_KEY
context totrue
(default:false
), which in combination withTIMEZONE_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