Skip to content

Commit 14401c2

Browse files
[Form] fix support for years outside of the 32b range on x86 arch
1 parent 8b6d1b9 commit 14401c2

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
@@ -674,17 +674,22 @@ private static function evaluateScalar(string $scalar, int $flags, array &$refer
674674
case Parser::preg_match('/^(-|\+)?[0-9][0-9_]*(\.[0-9_]+)?$/', $scalar):
675675
return (float) str_replace('_', '', $scalar);
676676
case Parser::preg_match(self::getTimestampRegex(), $scalar):
677+
// When no timezone is provided in the parsed date, YAML spec says we must assume UTC.
678+
$time = new \DateTime($scalar, new \DateTimeZone('UTC'));
679+
677680
if (Yaml::PARSE_DATETIME & $flags) {
678-
// When no timezone is provided in the parsed date, YAML spec says we must assume UTC.
679-
return new \DateTime($scalar, new \DateTimeZone('UTC'));
681+
return $time;
680682
}
681683

682-
$timeZone = date_default_timezone_get();
683-
date_default_timezone_set('UTC');
684-
$time = strtotime($scalar);
685-
date_default_timezone_set($timeZone);
684+
try {
685+
if (false !== $scalar = $time->getTimestamp()) {
686+
return $scalar;
687+
}
688+
} catch (\ValueError $e) {
689+
// no-op
690+
}
686691

687-
return $time;
692+
return $time->format('U');
688693
}
689694
}
690695

Tests/InlineTest.php

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

328328
['"a \\"string\\" with \'quoted strings inside\'"', 'a "string" with \'quoted strings inside\''],
329329
["'a \"string\" with ''quoted strings inside'''", 'a "string" with \'quoted strings inside\''],
@@ -394,7 +394,7 @@ public function getTestsForParseWithMapObjects()
394394
['2007-10-30T02:59:43Z', gmmktime(2, 59, 43, 10, 30, 2007)],
395395
['2007-10-30 02:59:43 Z', gmmktime(2, 59, 43, 10, 30, 2007)],
396396
['1960-10-30 02:59:43 Z', gmmktime(2, 59, 43, 10, 30, 1960)],
397-
['1730-10-30T02:59:43Z', gmmktime(2, 59, 43, 10, 30, 1730)],
397+
['1730-10-30T02:59:43Z', \PHP_INT_SIZE === 4 ? '-7547547617' : gmmktime(2, 59, 43, 10, 30, 1730)],
398398

399399
['"a \\"string\\" with \'quoted strings inside\'"', 'a "string" with \'quoted strings inside\''],
400400
["'a \"string\" with ''quoted strings inside'''", 'a "string" with \'quoted strings inside\''],

0 commit comments

Comments
 (0)