diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index 6853e5a0ba2cc..68ff14983f3ae 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -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) { @@ -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(); diff --git a/src/Symfony/Component/Yaml/Tests/InlineTest.php b/src/Symfony/Component/Yaml/Tests/InlineTest.php index e6e09084c5d6e..d6d7790dda413 100644 --- a/src/Symfony/Component/Yaml/Tests/InlineTest.php +++ b/src/Symfony/Component/Yaml/Tests/InlineTest.php @@ -507,7 +507,7 @@ 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)); $this->assertEquals($expected, Inline::parse($yaml, Yaml::PARSE_DATETIME)); } @@ -515,9 +515,9 @@ public function testParseTimestampAsDateTimeObject($yaml, $year, $month, $day, $ 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), ); } @@ -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]}";