Skip to content

[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

Conversation

remi-blaise
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets #11838
License MIT
Doc PR

@remi-blaise remi-blaise changed the title [Yaml] [Deprecation] Support parsing YAML timestamps as DateTime [Yaml] Support parsing YAML timestamps as DateTime Apr 21, 2015
@xabbuh xabbuh added the Yaml label Apr 21, 2015
@remi-blaise
Copy link
Contributor Author

Hey !

@@ -104,6 +108,18 @@ public static function dump($value, $exceptionOnInvalidType = false, $objectSupp

return 'null';
case is_object($value):
if ($value instanceof \DateTime) {
Copy link
Contributor

Choose a reason for hiding this comment

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

DateTimeInterface

Copy link
Member

Choose a reason for hiding this comment

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

The DateTimeInterface is not available in PHP 5.3.

Copy link
Member

Choose a reason for hiding this comment

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

So actually we should check for both concrete DateTimeInterface implementations:

if ($value instanceof \DateTime || $value instanceof \DateTimeImmutable) {
    // ...
}

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.

@dosten
Copy link
Contributor

dosten commented May 2, 2015

2.7 is feature frozen, so the target branch should be 2.8

deprecated in favor of the new `getPath()` method.


Yaml
Copy link
Contributor

Choose a reason for hiding this comment

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

This info should be in the CHANGELOG.md file of the Yaml component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ha ok. I didn't understand why only fappot writte the CHANGELOG so I didn't touch it. I didn't know there were CHANGELOG for each component.

@remi-blaise
Copy link
Contributor Author

@dosten How can I change the target branch ?

@dosten
Copy link
Contributor

dosten commented May 2, 2015

@Zzortell you don't need to do anything, if your PR gets accepted, a merger will merge this in 2.8 instead of 2.7.

@remi-blaise
Copy link
Contributor Author

Oki

@@ -104,6 +108,18 @@ public static function dump($value, $exceptionOnInvalidType = false, $objectSupp

return 'null';
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)

@@ -104,6 +108,18 @@ public static function dump($value, $exceptionOnInvalidType = false, $objectSupp

return 'null';
case is_object($value):
if ($value instanceof \DateTime || $value instanceof \DateTimeImmutable) {
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.

@fabpot
Copy link
Member

fabpot commented Feb 15, 2016

Now that we have flag support in YAML (as of 3.1), this one could be reconsidered. What do you think @xabbuh?

@xabbuh
Copy link
Member

xabbuh commented Feb 15, 2016

I agree.

@Zzortell Do you think you will be able to finish here or should I take over?

@xabbuh
Copy link
Member

xabbuh commented Feb 17, 2016

closing in favour of #17836

@xabbuh xabbuh closed this Feb 17, 2016
fabpot added a commit that referenced this pull request Feb 18, 2016
…buh)

This PR was merged into the 3.1-dev branch.

Discussion
----------

[Yaml] support to parse and dump DateTime objects

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #6275, #8580, #11838, #14420
| License       | MIT
| Doc PR        | TODO

Commits
-------

7e1c6c4 [Yaml] support to parse and dump DateTime objects
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants