Skip to content

Commit 5559a8c

Browse files
Merge branch '5.2' into 5.3
* 5.2: [Form] fix support for years outside of the 32b range on x86 arch Add an upgrade note about the removal of Serializable
2 parents a1385d6 + 1b0476c commit 5559a8c

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

Inline.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -692,17 +692,22 @@ private static function evaluateScalar(string $scalar, int $flags, array &$refer
692692
case Parser::preg_match('/^(-|\+)?[0-9][0-9_]*(\.[0-9_]+)?$/', $scalar):
693693
return (float) str_replace('_', '', $scalar);
694694
case Parser::preg_match(self::getTimestampRegex(), $scalar):
695+
// When no timezone is provided in the parsed date, YAML spec says we must assume UTC.
696+
$time = new \DateTime($scalar, new \DateTimeZone('UTC'));
697+
695698
if (Yaml::PARSE_DATETIME & $flags) {
696-
// When no timezone is provided in the parsed date, YAML spec says we must assume UTC.
697-
return new \DateTime($scalar, new \DateTimeZone('UTC'));
699+
return $time;
698700
}
699701

700-
$timeZone = date_default_timezone_get();
701-
date_default_timezone_set('UTC');
702-
$time = strtotime($scalar);
703-
date_default_timezone_set($timeZone);
702+
try {
703+
if (false !== $scalar = $time->getTimestamp()) {
704+
return $scalar;
705+
}
706+
} catch (\ValueError $e) {
707+
// no-op
708+
}
704709

705-
return $time;
710+
return $time->format('U');
706711
}
707712
}
708713

Tests/InlineTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ public function getTestsForParse()
326326
['2007-10-30T02:59:43Z', gmmktime(2, 59, 43, 10, 30, 2007)],
327327
['2007-10-30 02:59:43 Z', gmmktime(2, 59, 43, 10, 30, 2007)],
328328
['1960-10-30 02:59:43 Z', gmmktime(2, 59, 43, 10, 30, 1960)],
329-
['1730-10-30T02:59:43Z', gmmktime(2, 59, 43, 10, 30, 1730)],
329+
['1730-10-30T02:59:43Z', \PHP_INT_SIZE === 4 ? '-7547547617' : gmmktime(2, 59, 43, 10, 30, 1730)],
330330

331331
['"a \\"string\\" with \'quoted strings inside\'"', 'a "string" with \'quoted strings inside\''],
332332
["'a \"string\" with ''quoted strings inside'''", 'a "string" with \'quoted strings inside\''],
@@ -397,7 +397,7 @@ public function getTestsForParseWithMapObjects()
397397
['2007-10-30T02:59:43Z', gmmktime(2, 59, 43, 10, 30, 2007)],
398398
['2007-10-30 02:59:43 Z', gmmktime(2, 59, 43, 10, 30, 2007)],
399399
['1960-10-30 02:59:43 Z', gmmktime(2, 59, 43, 10, 30, 1960)],
400-
['1730-10-30T02:59:43Z', gmmktime(2, 59, 43, 10, 30, 1730)],
400+
['1730-10-30T02:59:43Z', \PHP_INT_SIZE === 4 ? '-7547547617' : gmmktime(2, 59, 43, 10, 30, 1730)],
401401

402402
['"a \\"string\\" with \'quoted strings inside\'"', 'a "string" with \'quoted strings inside\''],
403403
["'a \"string\" with ''quoted strings inside'''", 'a "string" with \'quoted strings inside\''],

0 commit comments

Comments
 (0)