Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fdb7834

Browse files
Merge branch '3.1'
* 3.1: [Yaml] Fix 7.1 compat
2 parents 3a86cee + c3b9690 commit fdb7834

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/Symfony/Component/Yaml/Inline.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,10 @@ private static function evaluateScalar($scalar, $flags, $references = array())
645645
return (float) str_replace(array(',', '_'), '', $scalar);
646646
case preg_match(self::getTimestampRegex(), $scalar):
647647
if (Yaml::PARSE_DATETIME & $flags) {
648-
return new \DateTime($scalar, new \DateTimeZone('UTC'));
648+
$date = new \DateTime($scalar);
649+
$date->setTimeZone(new \DateTimeZone('UTC'));
650+
651+
return $date;
649652
}
650653

651654
$timeZone = date_default_timezone_get();

src/Symfony/Component/Yaml/Tests/InlineTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -566,17 +566,17 @@ public function testParseTimestampAsDateTimeObject($yaml, $year, $month, $day, $
566566
$expected = new \DateTime($yaml);
567567
$expected->setTimeZone(new \DateTimeZone('UTC'));
568568
$expected->setDate($year, $month, $day);
569-
$expected->setTime($hour, $minute, $second);
569+
@$expected->setTime($hour, $minute, $second, 1000000 * ($second - (int) $second));
570570

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

574574
public function getTimestampTests()
575575
{
576576
return array(
577-
'canonical' => array('2001-12-15T02:59:43.1Z', 2001, 12, 15, 2, 59, 43),
578-
'ISO-8601' => array('2001-12-15t21:59:43.10-05:00', 2001, 12, 16, 2, 59, 43),
579-
'spaced' => array('2001-12-15 21:59:43.10 -5', 2001, 12, 16, 2, 59, 43),
577+
'canonical' => array('2001-12-15T02:59:43.1Z', 2001, 12, 15, 2, 59, 43.1),
578+
'ISO-8601' => array('2001-12-15t21:59:43.10-05:00', 2001, 12, 16, 2, 59, 43.1),
579+
'spaced' => array('2001-12-15 21:59:43.10 -5', 2001, 12, 16, 2, 59, 43.1),
580580
'date' => array('2001-12-15', 2001, 12, 15, 0, 0, 0),
581581
);
582582
}
@@ -589,7 +589,7 @@ public function testParseNestedTimestampListAsDateTimeObject($yaml, $year, $mont
589589
$expected = new \DateTime($yaml);
590590
$expected->setTimeZone(new \DateTimeZone('UTC'));
591591
$expected->setDate($year, $month, $day);
592-
$expected->setTime($hour, $minute, $second);
592+
@$expected->setTime($hour, $minute, $second, 1000000 * ($second - (int) $second));
593593

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

0 commit comments

Comments
 (0)