Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Serializer] Allow forcing timezone inDateTimeNormalizer 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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation
carsonbot commentedApr 5, 2025
Hey! I see that this is your first PR. That is great! Welcome! Symfony has acontribution 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 |
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 denormalizationsrc/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
mdriessen commentedOct 31, 2025
Is there anything I can do to help this being merged in Symfony 7.4? |
Uh oh!
There was an error while loading.Please reload this page.
551c4f8 to8b9a4f9Comparesrc/Symfony/Component/Serializer/Context/Normalizer/DateTimeNormalizerContextBuilder.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
e95ddf0 todacfe45CompareDateTimeNormalizer during denormalizationDateTimeNormalizer during denormalization@nicolas-grekas Thanks for the feedback. The branch is now up-to-date again with 7.4. There are 3 failings tests but I don't see the relation to my changes though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I almost forgot: Mapping/Loader/schema/serialization.schema.json needs also an update
| * @throws InvalidArgumentException | ||
| */ | ||
| publicfunctionwithTimezone(\DateTimeZone|string|null$timezone):static | ||
| publicfunctionwithTimezone(\DateTimeZone|string|null$timezone, ?bool$force =null):static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
| publicfunction withTimezone(\DateTimeZone|string|null$timezone,?bool$force =null):static | |
| publicfunction withTimezone(\DateTimeZone|string|null$timezone,bool$force =false):static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I thought about setting it totrue|false but in the implementation there's a "default context" and given context. Basicly you could set default context to->withTimezone(null, true), and in your custom context->withTimezone('UTC, null). In this way forevery context the timezone will be forced, but per serializer context you can enforce different timezones.
src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
2 nits and GTM, thanks
src/Symfony/Component/Serializer/Context/Normalizer/DateTimeNormalizerContextBuilder.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Serializer/Mapping/Loader/schema/serialization.schema.json OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Thank you@frankdekker. |
c5d0e49 intosymfony:7.4Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
By default the
DateTimeNormalizerwill denormalize timestamps and date strings that include a timezone toDateTimeobjects with respective timezone UTC or the timezone from the date string. Even with the context keyTIMEZONE_KEYset, the timezone from the input superceeds the context timezone.This PR allows to set
PRESERVE_CONTEXT_TIMEZONE_KEYcontext totrue(default:false), which in combination withTIMEZONE_KEYwill set the Timezone of the denormalized DateTimes to the given timezone. The timezone from the input will be overwritten.Documentation
symfony/symfony-docs#20860