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

[Yaml] Support parsing YAML timestamps as DateTime #14420

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 12 commits into from
Closed
Prev Previous commit
Next Next commit
[Yaml] Delete a cast
  • Loading branch information
remi-blaise committed May 2, 2015
commit 028f2d72a19f8f9d8a397d19804c11b9b075414a
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Yaml/Inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static function dump($value, $exceptionOnInvalidType = false, $objectSupp
case is_object($value):
if ($value instanceof \DateTime || $value instanceof \DateTimeImmutable) {
Copy link
Member

Choose a reason for hiding this comment

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

use DateTimeInterface rather than DateTimeImmutable. This way, the DateTimeInterface check covers all supported cases for PHP 5.5+ (and we can drop the DateTime check in 3.0 when dropping the PHP 5.4 support)

if ($value->getTimezone()->getName() === date_default_timezone_get()) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about this. The code parsing the date might have a different default timezone. It is better to always include all info IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, if the TimeZone has been intentionally defined as for exemple +1 (in the YAML file parsed or in the PHP datas), it dumps it (because the server server timestamp is for example Europe/Paris and not +1).
If it was not defined manually, it has the default TimeZone and so the Yaml component doesn't dump the timestamp (letting it with default value in some ways).
I think personally it's the best behaviour.

Copy link
Member

Choose a reason for hiding this comment

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

What if it was explicitly defined as UTC and the server default timezone is also UTC ? You have no way to know whether the UTC timezone was explicitly chosen or no. But even worse, you have no idea how this will be parsed. So IMO, you should not drop information when dumping, assuming that the server parsing your YAML will have the same config

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok.

if (0 === (int) $value->format('His')) {
if ('000000' === $value->format('His')) {
return $value->format('Y-m-d');
}

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.