Fix #27378: Error when rendering a DateIntervalType form with exactly 0 weeks

This commit is contained in:
karl.rixon 2018-05-25 14:40:09 +01:00
parent 13e983a127
commit dae704ad2f
2 changed files with 16 additions and 1 deletions

View File

@ -89,7 +89,7 @@ class DateIntervalToArrayTransformer implements DataTransformerInterface
$result[$field] = $dateInterval->format('%'.($this->pad ? strtoupper($char) : $char));
}
if (in_array('weeks', $this->fields, true)) {
$result['weeks'] = 0;
$result['weeks'] = '0';
if (isset($result['days']) && (int) $result['days'] >= 7) {
$result['weeks'] = (string) floor($result['days'] / 7);
$result['days'] = (string) ($result['days'] % 7);

View File

@ -90,6 +90,21 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase
$this->assertSame($output, $input);
}
public function testTransformWithZeroWeek()
{
$transformer = new DateIntervalToArrayTransformer(array('weeks', 'minutes', 'seconds'));
$input = new \DateInterval('P1Y2M0WT4H5M6S');
$output = array(
'weeks' => '0',
'minutes' => '5',
'seconds' => '6',
);
$input = $transformer->transform($input);
ksort($input);
ksort($output);
$this->assertSame($output, $input);
}
public function testTransformDaysToWeeks()
{
$transformer = new DateIntervalToArrayTransformer(array('weeks', 'minutes', 'seconds'));