-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Provide option to always apply timezone of the DateTimeNormalizer context. #31256
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Incorporate changes as suggested by @fabpot
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,11 +26,11 @@ class DateTimeNormalizer implements NormalizerInterface, DenormalizerInterface, | |
const TIMEZONE_KEY = 'datetime_timezone'; | ||
|
||
/** | ||
* In PHP, The $timezone parameter and the current timezone are ignored when the $time parameter either is a UNIX timestamp (e.g. @946684800) or specifies a timezone (e.g. 2010-01-28T15:00:00+02:00). | ||
* In PHP, the $timezone parameter and the current timezone are ignored when the $time parameter either is a UNIX timestamp (e.g. @946684800) or specifies a timezone (e.g. 2010-01-28T15:00:00+02:00). | ||
* | ||
* The denormalizer assumes that all DateTimeInterface object returned will have the timezone returned by the getTimezone() method. | ||
* Default PHP behavior will occur if the getTimezone() method returns null or context[self::PRESERVE_CONTEXT_TIMEZONE] is set to false. | ||
* This flag will be ignored in Symfony/Serializer 5.0+ | ||
* This flag will be ignored in Symfony 5.0+ | ||
*/ | ||
const PRESERVE_CONTEXT_TIMEZONE = 'preserve_context_timezone'; | ||
crayner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
@@ -53,14 +53,14 @@ public function __construct($defaultContext = [], \DateTimeZone $timezone = null | |
]; | ||
|
||
if (!\is_array($defaultContext)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
@trigger_error('Passing configuration options directly to the constructor is deprecated since Symfony 4.2, use the default context instead.', E_USER_DEPRECATED); | ||
@trigger_error('Passing the date time format directly to the constructor is deprecated since Symfony 4.2, use the default context instead.', E_USER_DEPRECATED); | ||
|
||
$defaultContext = [self::FORMAT_KEY => (string) $defaultContext]; | ||
$defaultContext[self::TIMEZONE_KEY] = $timezone; | ||
} | ||
|
||
if (!isset($defaultContext[self::TIMEZONE_KEY]) && null !== $timezone) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a $timezone and $defaultContext was not always an array when this was written. |
||
@trigger_error('Passing configuration options directly to the constructor is deprecated since Symfony 4.2, use the default context instead.', E_USER_DEPRECATED); | ||
@trigger_error('Passing the time zone directly to the constructor is deprecated since Symfony 4.2, use the default context instead.', E_USER_DEPRECATED); | ||
|
||
$defaultContext[self::TIMEZONE_KEY] = $timezone; | ||
} | ||
|
@@ -193,7 +193,7 @@ private function getTimezone(array $context) | |
|
||
private function isPreserveContextTimezone(array $context): bool | ||
{ | ||
//Version 5.0 of Symfony/Serializer will always preserve the context timezone, so this method always will return true, unless the timezone equals null. | ||
// Version 5.0 of Symfony/Serializer will always preserve the context timezone, so this method always will return true, unless the timezone equals null. | ||
if (null === $this->getTimezone($context)) { | ||
return false; | ||
} | ||
|
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.
6.0?