Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[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

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update DateTimeNormalizer.php
Incorporate changes as suggested by @fabpot
  • Loading branch information
crayner authored Jul 8, 2019
commit 1dd23a2ca494135157224bce65779ec74227046d
Original file line number Diff line number Diff line change
Expand Up @@ -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+
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6.0?

*/
const PRESERVE_CONTEXT_TIMEZONE = 'preserve_context_timezone';
crayner marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -53,14 +53,14 @@ public function __construct($defaultContext = [], \DateTimeZone $timezone = null
];

if (!\is_array($defaultContext)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$defaultContext is always an array as there is a type hint in the constructor signature.

@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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no $timezone variable in the constructor.

Copy link
Author

Choose a reason for hiding this comment

The 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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.