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

Skip to content

Commit c2b43ed

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

File tree

7 files changed

+29
-27
lines changed

7 files changed

+29
-27
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: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public static function create(?string $locale, ?int $datetype, ?int $timetype, $
182182
/**
183183
* Format the date/time value (timestamp) as a string.
184184
*
185-
* @param int|\DateTimeInterface $timestamp The timestamp to format
185+
* @param int|string|\DateTimeInterface $timestamp The timestamp to format
186186
*
187187
* @return string|bool The formatted value or false if formatting failed
188188
*
@@ -194,11 +194,15 @@ public function format($timestamp)
194194
{
195195
// intl allows timestamps to be passed as arrays - we don't
196196
if (\is_array($timestamp)) {
197-
$message = 'Only integer Unix timestamps and DateTime objects are supported';
197+
$message = 'Only Unix timestamps and DateTime objects are supported';
198198

199199
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'timestamp', $timestamp, $message);
200200
}
201201

202+
if (\is_string($timestamp) && $dt = \DateTime::createFromFormat('U', $timestamp)) {
203+
$timestamp = $dt;
204+
}
205+
202206
// behave like the intl extension
203207
$argumentError = null;
204208
if (!\is_int($timestamp) && !$timestamp instanceof \DateTimeInterface) {
@@ -214,7 +218,7 @@ public function format($timestamp)
214218
}
215219

216220
if ($timestamp instanceof \DateTimeInterface) {
217-
$timestamp = $timestamp->getTimestamp();
221+
$timestamp = $timestamp->format('U');
218222
}
219223

220224
$transformer = new FullTransformer($this->getPattern(), $this->getTimeZoneId());
@@ -583,10 +587,9 @@ public function setTimeZone($timeZone)
583587
*
584588
* @return \DateTime
585589
*/
586-
protected function createDateTime(int $timestamp)
590+
protected function createDateTime($timestamp)
587591
{
588-
$dateTime = new \DateTime();
589-
$dateTime->setTimestamp($timestamp);
592+
$dateTime = \DateTime::createFromFormat('U', $timestamp);
590593
$dateTime->setTimezone($this->dateTimeZone);
591594

592595
return $dateTime;

src/Symfony/Component/Intl/Tests/DateFormatter/IntlDateFormatterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function testFormatWithUnsupportedTimestampArgument()
7575
} catch (\Exception $e) {
7676
$this->assertInstanceOf(MethodArgumentValueNotImplementedException::class, $e);
7777

78-
$this->assertStringEndsWith('Only integer Unix timestamps and DateTime objects are supported. Please install the "intl" extension for full localization capabilities.', $e->getMessage());
78+
$this->assertStringEndsWith('Only Unix timestamps and DateTime objects are supported. Please install the "intl" extension for full localization capabilities.', $e->getMessage());
7979
}
8080
}
8181

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)