Skip to content

[Yaml] Fix 7.1 compat #20291

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
Oct 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/Symfony/Component/Yaml/Inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public static function parseScalar($scalar, $flags = 0, $delimiters = null, $str
}

if ($output && '%' === $output[0]) {
@trigger_error(sprintf('Not quoting the scalar "%s" starting with the "%%" indicator character is deprecated since Symfony 3.1 and will throw a ParseException in 4.0.' , $output), E_USER_DEPRECATED);
@trigger_error(sprintf('Not quoting the scalar "%s" starting with the "%%" indicator character is deprecated since Symfony 3.1 and will throw a ParseException in 4.0.', $output), E_USER_DEPRECATED);
}

if ($evaluate) {
Expand Down Expand Up @@ -606,7 +606,10 @@ private static function evaluateScalar($scalar, $flags, $references = array())
return (float) str_replace(',', '', $scalar);
case preg_match(self::getTimestampRegex(), $scalar):
if (Yaml::PARSE_DATETIME & $flags) {
return new \DateTime($scalar, new \DateTimeZone('UTC'));
$date = new \DateTime($scalar);
$date->setTimeZone(new \DateTimeZone('UTC'));

return $date;
}

$timeZone = date_default_timezone_get();
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Component/Yaml/Tests/InlineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,17 +507,17 @@ public function testParseTimestampAsDateTimeObject($yaml, $year, $month, $day, $
$expected = new \DateTime($yaml);
$expected->setTimeZone(new \DateTimeZone('UTC'));
$expected->setDate($year, $month, $day);
$expected->setTime($hour, $minute, $second);
@$expected->setTime($hour, $minute, $second, 1000000 * ($second - (int) $second));
Copy link
Member

Choose a reason for hiding this comment

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

why do we need to silent it now ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because the method takes 3 args before 7.1, and 4 since 7.1 ($microseconds)

Copy link
Member

Choose a reason for hiding this comment

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

Why not making the call dependent on the executed PHP version then?

Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Member Author

Choose a reason for hiding this comment

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

I had HHVM in mind, I don't know if the version check will be valid (now or later when they'll implement this). Do as you prefer :)


$this->assertEquals($expected, Inline::parse($yaml, Yaml::PARSE_DATETIME));
}

public function getTimestampTests()
{
return array(
'canonical' => array('2001-12-15T02:59:43.1Z', 2001, 12, 15, 2, 59, 43),
'ISO-8601' => array('2001-12-15t21:59:43.10-05:00', 2001, 12, 16, 2, 59, 43),
'spaced' => array('2001-12-15 21:59:43.10 -5', 2001, 12, 16, 2, 59, 43),
'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),
);
}
Expand All @@ -530,7 +530,7 @@ public function testParseNestedTimestampListAsDateTimeObject($yaml, $year, $mont
$expected = new \DateTime($yaml);
$expected->setTimeZone(new \DateTimeZone('UTC'));
$expected->setDate($year, $month, $day);
$expected->setTime($hour, $minute, $second);
@$expected->setTime($hour, $minute, $second, 1000000 * ($second - (int) $second));

$expectedNested = array('nested' => array($expected));
$yamlNested = "{nested: [$yaml]}";
Expand Down