Fix DateType for 32bits computers.

This commit is contained in:
WedgeSama 2013-10-17 09:16:34 +02:00 committed by Fabien Potencier
parent 3aa4e14d07
commit 2f9bb75174
2 changed files with 24 additions and 1 deletions

View File

@ -300,7 +300,9 @@ class DateType extends AbstractType
$result = array();
foreach ($years as $year) {
$result[$year] = gmmktime(0, 0, 0, 6, 15, $year);
if (false !== $y = gmmktime(0, 0, 0, 6, 15, $year)) {
$result[$year] = $y;
}
}
return $result;

View File

@ -774,4 +774,25 @@ class DateTypeTest extends LocalizedTestCase
$this->assertSame(array(), $form['day']->getErrors());
$this->assertSame(array($error), $form->getErrors());
}
public function testYearsFor32BitsMachines()
{
if (4 !== PHP_INT_SIZE) {
$this->markTestSkipped(
'PHP must be compiled in 32 bit mode to run this test');
}
$form = $this->factory->create('date', null, array(
'years' => range(1900, 2040),
));
$view = $form->createView();
$listChoices = array();
foreach(range(1902, 2037) as $y) {
$listChoices[] = new ChoiceView($y, $y, $y);
}
$this->assertEquals($listChoices, $view['year']->vars['choices']);
}
}