8000 [Form] fix support for years in on x86 arch · symfony/symfony@91403ca · GitHub
[go: up one dir, main page]

Skip to content

Commit 91403ca

Browse files
[Form] fix support for years in on x86 arch
1 parent 0b81b38 commit 91403ca

File tree

6 files changed

+22
-24
lines changed

6 files changed

+22
-24
lines changed

src/Symfony/Component/Form/Extension/Core/Type/DateType.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,7 @@ private function listYears(array $years)
375375
$result = [];
376376

377377
foreach ($years as $year) {
378-
if (false !== $y = gmmktime(0, 0, 0, 6, 15, $year)) {
379-
$result[$y] = $year;
380-
}
378+
$result[\PHP_INT_SIZE === 4 ? \DateTime::createFromFormat('Y e', $year.' UTC')->format('U') : gmmktime(0, 0, 0, 6, 15, $year)] = $year;
381379
}
382380

383381
return $result;

src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -927,19 +927,15 @@ public function testDayErrorsBubbleUp($widget)
927927
$this->assertSame([$error], iterator_to_array($form->getErrors()));
928928
}
929929

930-
public function testYearsFor32BitsMachines()
930+
public function testYears()
931931
{
932-
if (4 !== \PHP_INT_SIZE) {
933-
$this->markTestSkipped('PHP 32 bit is required.');
934-
}
935-
936932
$view = $this->factory->create(static::TESTED_TYPE, null, [
937-
'years' => range(1900, 2040),
933+
'years' => [1900, 2000, 2040],
938934
])
939935
->createView();
940936

941937
$listChoices = [];
942-
foreach (range(1902, 2037) as $y) {
938+
foreach ([1900, 2000, 2040] as $y) {
943939
$listChoices[] = new ChoiceView($y, $y, $y);
944940
}
945941

src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public function format($timestamp)
214214
}
215215

216216
if ($timestamp instanceof \DateTimeInterface) {
217-
$timestamp = $timestamp->getTimestamp();
217+
$timestamp = $timestamp->format('U');
218218
}
219219

220220
$transformer = new FullTransformer($this->getPattern(), $this->getTimeZoneId());
@@ -583,10 +583,9 @@ public function setTimeZone($timeZone)
583583
*
584584
* @return \DateTime
585585
*/
586-
protected function createDateTime(int $timestamp)
586+
protected function createDateTime($timestamp)
587587
{
588-
$dateTime = new \DateTime();
589-
$dateTime->setTimestamp($timestamp);
588+
$dateTime = \DateTime::createFromFormat('U', $timestamp);
590589
$dateTime->setTimezone($this->dateTimeZone);
591590

592591
return $dateTime;

src/Symfony/Component/Security/Http/Tests/RememberMe/PersistentRememberMeHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function testConsumeRememberMeCookieExpired()
118118
$this->tokenProvider->expects($this->any())
119119
->method('loadTokenBySeries')
120120
->with('series1')
121-
->willReturn(new PersistentToken(InMemoryUser::class, 'wouter', 'series1', 'tokenvalue', new \DateTime('-'.(31536000 - 1).' years')));
121+
->willReturn(new PersistentToken(InMemoryUser::class, 'wouter', 'series1', 'tokenvalue', new \DateTime('-'.(31536000 - 1).' months')));
122122

123123
$this->tokenProvider->expects($this->never())->method('updateToken')->with('series1');
124124

src/Symfony/Component/Yaml/Inline.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -673,17 +673,22 @@ private static function evaluateScalar(string $scalar, int $flags, array &$refer
673673
case Parser::preg_match('/^(-|\+)?[0-9][0-9_]*(\.[0-9_]+)?$/', $scalar):
674674
return (float) str_replace('_', '', $scalar);
675675
case Parser::preg_match(self::getTimestampRegex(), $scalar):
676+
// When no timezone is provided in the parsed date, YAML spec says we must assume UTC.
677+
$time = new \DateTime($scalar, new \DateTimeZone('UTC'));
678+
676679
if (Yaml::PARSE_DATETIME & $flags) {
677-
// When no timezone is provided in the parsed date, YAML spec says we must assume UTC.
678-
return new \DateTime($scalar, new \DateTimeZone('UTC'));
680+
return $time;
679681
}
680682

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

686-
return $time;
691+
return $time->format('U');
687692
}
688693
}
689694

src/Symfony/Component/Yaml/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)
0