8000 bug #9314 [Form] Fix DateType for 32bits computers. (WedgeSama) · symfony/symfony@9b99f09 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9b99f09

Browse files
committed
bug #9314 [Form] Fix DateType for 32bits computers. (WedgeSama)
This PR was squashed before being merged into the 2.2 branch (closes #9314). Discussion ---------- [Form] Fix DateType for 32bits computers. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #5227,#5554 | License | MIT | Doc PR | - Fix an issue due to 32bits machines, date can be only between 1902-2037. Simply not add date if false. Can be good to add this to 2.3 and master too. Commits ------- b80fb43 [Form] Fix DateType for 32bits computers.
2 parents 3aa4e14 + 2f9bb75 commit 9b99f09

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,9 @@ private function listYears(array $years)
300300
$result = array();
301301

302302
foreach ($years as $year) {
303-
$result[$year] = gmmktime(0, 0, 0, 6, 15, $year);
303+
if (false !== $y = gmmktime(0, 0, 0, 6, 15, $year)) {
304+
$result[$year] = $y;
305+
}
304306
}
305307

306308
return $result;

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,4 +774,25 @@ public function testDayErrorsBubbleUp($widget)
774774
$this->assertSame(array(), $form['day']->getErrors());
775775
$this->assertSame(array($error), $form->getErrors());
776776
}
777+
778+
public function testYearsFor32BitsMachines()
779+
{
780+
if (4 !== PHP_INT_SIZE) {
781+
$this->markTestSkipped(
782+
'PHP must be compiled in 32 bit mode to run this test');
783+
}
784+
785+
$form = $this->factory->create('date', null, array(
786+
'years' => range(1900, 2040),
787+
));
788+
789+
$view = $form->createView();
790+
791+
$listChoices = array();
792+
foreach(range(1902, 2037) as $y) {
793+
$listChoices[] = new ChoiceView($y, $y, $y);
794+
}
795+
796+
$this->assertEquals($listChoices, $view['year']->vars['choices']);
797+
}
777798
}

0 commit comments

Comments
 (0)
0