Skip to content

[Yaml] support to parse and dump DateTime objects #17836

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

Merged
merged 1 commit into from
Feb 18, 2016

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Feb 17, 2016

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 symfony/symfony-docs#6226

* Added support for parsing timestamps as `\DateTime` objects:

```php
Yaml::parse('2001-12-15 21:59:43.10 -5', Yaml::Parse_DATETIME);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be capitalized: Yaml::PARSE_DATETIME.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. :) Thanks!

@xabbuh xabbuh force-pushed the issue-11838 branch 2 times, most recently from dbd6af3 to fabf9ae Compare February 17, 2016 22:22
@@ -568,8 +574,15 @@ private static function evaluateScalar($scalar, $references = array())
return log(0);
case preg_match('/^(-|\+)?[0-9,]+(\.[0-9]+)?$/', $scalar):
return (float) str_replace(',', '', $scalar);
case preg_match(self::getTimestampRegex(), $scalar) && Yaml::PARSE_DATETIME & $flags:
return new \DateTime($scalar,new \DateTimeZone('UTC'));
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this into the next case to avoid matching twice?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, makes sense. Did that.

@xabbuh xabbuh force-pushed the issue-11838 branch 2 times, most recently from 1c6ca6f to 975eddf Compare February 18, 2016 09:40
@stof
Copy link
Member

stof commented Feb 18, 2016

👍

@fabpot
Copy link
Member

fabpot commented Feb 18, 2016

Thank you @xabbuh.

@fabpot fabpot merged commit 7e1c6c4 into symfony:master Feb 18, 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
@xabbuh xabbuh deleted the issue-11838 branch February 18, 2016 12:17
@xabbuh xabbuh mentioned this pull request Mar 1, 2016
7 tasks
@fabpot fabpot mentioned this pull request May 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants