-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Conversation
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 |
3c35bdf
to
2f02c57
Compare
* Added support for parsing timestamps as `\DateTime` objects: | ||
|
||
```php | ||
Yaml::parse('2001-12-15 21:59:43.10 -5', Yaml::Parse_DATETIME); |
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.
Should be capitalized: Yaml::PARSE_DATETIME
.
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.
Good catch. :) Thanks!
dbd6af3
to
fabf9ae
Compare
@@ -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')); |
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.
Can we move this into the next case
to avoid matching twice?
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.
Sure, makes sense. Did that.
1c6ca6f
to
975eddf
Compare
👍 |
Thank you @xabbuh. |
…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