Skip to content

Commit f2300ba

Browse files
Merge branch '3.1'
* 3.1: [YAML] Fix processing timestamp with timezone [ci] Testing with UTC hides bugs [DI] Fix error when trying to resolve a DefinitionDecorator [DoctrineBridge] Fix deprecation message/documentation of implementing UserProviderInterface using the entity provider Fix time-sensitive tests that use data providers [Validator] improve and added more Indonesian translation.
2 parents 92e2f6d + 9da3753 commit f2300ba

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

Inline.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -648,10 +648,8 @@ private static function evaluateScalar($scalar, $flags, $references = array())
648648
return (float) str_replace(array(',', '_'), '', $scalar);
649649
case preg_match(self::getTimestampRegex(), $scalar):
650650
if (Yaml::PARSE_DATETIME & $flags) {
651-
$date = new \DateTime($scalar);
652-
$date->setTimeZone(new \DateTimeZone('UTC'));
653-
654-
return $date;
651+
// When no timezone is provided in the parsed date, YAML spec says we must assume UTC.
652+
return new \DateTime($scalar, new \DateTimeZone('UTC'));
655653
}
656654

657655
$timeZone = date_default_timezone_get();

Tests/InlineTest.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ public function testParseTimestampAsUnixTimestampByDefault($yaml, $year, $month,
561561
/**
562562
* @dataProvider getTimestampTests
563563
*/
564-
public function testParseTimestampAsDateTimeObject($yaml, $year, $month, $day, $hour, $minute, $second)
564+
public function testParseTimestampAsDateTimeObject($yaml, $year, $month, $day, $hour, $minute, $second, $timezone)
565565
{
566566
$expected = new \DateTime($yaml);
567567
$expected->setTimeZone(new \DateTimeZone('UTC'));
@@ -573,16 +573,18 @@ public function testParseTimestampAsDateTimeObject($yaml, $year, $month, $day, $
573573
$expected->setTime($hour, $minute, $second);
574574
}
575575

576-
$this->assertEquals($expected, Inline::parse($yaml, Yaml::PARSE_DATETIME));
576+
$date = Inline::parse($yaml, Yaml::PARSE_DATETIME);
577+
$this->assertEquals($expected, $date);
578+
$this->assertSame($timezone, $date->format('O'));
577579
}
578580

579581
public function getTimestampTests()
580582
{
581583
return array(
582-
'canonical' => array('2001-12-15T02:59:43.1Z', 2001, 12, 15, 2, 59, 43.1),
583-
'ISO-8601' => array('2001-12-15t21:59:43.10-05:00', 2001, 12, 16, 2, 59, 43.1),
584-
'spaced' => array('2001-12-15 21:59:43.10 -5', 2001, 12, 16, 2, 59, 43.1),
585-
'date' => array('2001-12-15', 2001, 12, 15, 0, 0, 0),
584+
'canonical' => array('2001-12-15T02:59:43.1Z', 2001, 12, 15, 2, 59, 43.1, '+0000'),
585+
'ISO-8601' => array('2001-12-15t21:59:43.10-05:00', 2001, 12, 16, 2, 59, 43.1, '-0500'),
586+
'spaced' => array('2001-12-15 21:59:43.10 -5', 2001, 12, 16, 2, 59, 43.1, '-0500'),
587+
'date' => array('2001-12-15', 2001, 12, 15, 0, 0, 0, '+0000'),
586588
);
587589
}
588590

@@ -594,7 +596,11 @@ public function testParseNestedTimestampListAsDateTimeObject($yaml, $year, $mont
594596
$expected = new \DateTime($yaml);
595597
$expected->setTimeZone(new \DateTimeZone('UTC'));
596598
$expected->setDate($year, $month, $day);
597-
@$expected->setTime($hour, $minute, $second, 1000000 * ($second - (int) $second));
599+
if (PHP_VERSION_ID >= 70100) {
600+
$expected->setTime($hour, $minute, $second, 1000000 * ($second - (int) $second));
601+
} else {
602+
$expected->setTime($hour, $minute, $second);
603+
}
598604

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

0 commit comments

Comments
 (0)