-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[YAML] Fix processing timestamp strings with timezone #20550
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -502,7 +502,7 @@ public function testParseTimestampAsUnixTimestampByDefault($yaml, $year, $month, | |
/** | ||
* @dataProvider getTimestampTests | ||
*/ | ||
public function testParseTimestampAsDateTimeObject($yaml, $year, $month, $day, $hour, $minute, $second) | ||
public function testParseTimestampAsDateTimeObject($yaml, $year, $month, $day, $hour, $minute, $second, $timezone) | ||
{ | ||
$expected = new \DateTime($yaml); | ||
$expected->setTimeZone(new \DateTimeZone('UTC')); | ||
|
@@ -514,16 +514,18 @@ public function testParseTimestampAsDateTimeObject($yaml, $year, $month, $day, $ | |
$expected->setTime($hour, $minute, $second); | ||
} | ||
|
||
$this->assertEquals($expected, Inline::parse($yaml, Yaml::PARSE_DATETIME)); | ||
$date = Inline::parse($yaml, Yaml::PARSE_DATETIME); | ||
$this->assertEquals($expected, $date); | ||
$this->assertSame($timezone, $date->format('O')); | ||
} | ||
|
||
public function getTimestampTests() | ||
{ | ||
return array( | ||
'canonical' => array('2001-12-15T02:59:43.1Z', 2001, 12, 15, 2, 59, 43.1), | ||
'ISO-8601' => array('2001-12-15t21:59:43.10-05:00', 2001, 12, 16, 2, 59, 43.1), | ||
'spaced' => array('2001-12-15 21:59:43.10 -5', 2001, 12, 16, 2, 59, 43.1), | ||
'date' => array('2001-12-15', 2001, 12, 15, 0, 0, 0), | ||
'canonical' => array('2001-12-15T02:59:43.1Z', 2001, 12, 15, 2, 59, 43.1, '+0000'), | ||
'ISO-8601' => array('2001-12-15t21:59:43.10-05:00', 2001, 12, 16, 2, 59, 43.1, '-0500'), | ||
'spaced' => array('2001-12-15 21:59:43.10 -5', 2001, 12, 16, 2, 59, 43.1, '-0500'), | ||
'date' => array('2001-12-15', 2001, 12, 15, 0, 0, 0, '+0000'), | ||
); | ||
} | ||
|
||
|
@@ -535,7 +537,11 @@ public function testParseNestedTimestampListAsDateTimeObject($yaml, $year, $mont | |
$expected = new \DateTime($yaml); | ||
$expected->setTimeZone(new \DateTimeZone('UTC')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this was intended to cover HHVM. Not sure we should remove it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This patch is just adding consistency with another test in the same file. Looks like we missed it, maybe during a merge. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found it :) #20291 (comment) Ah.. i see the inconsistency now 👍 |
||
$expected->setDate($year, $month, $day); | ||
@$expected->setTime($hour, $minute, $second, 1000000 * ($second - (int) $second)); | ||
if (PHP_VERSION_ID >= 70100) { | ||
$expected->setTime($hour, $minute, $second, 1000000 * ($second - (int) $second)); | ||
} else { | ||
$expected->setTime($hour, $minute, $second); | ||
} | ||
|
||
$expectedNested = array('nested' => array($expected)); | ||
$yamlNested = "{nested: [$yaml]}"; | ||
|
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.
Given @nicolas-grekas comment, it could simply be
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.
Updated