Fix #27378: Error when rendering a DateIntervalType form with exactly 0 weeks
This commit is contained in:
parent
13e983a127
commit
dae704ad2f
@ -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);
|
||||
|
@ -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'));
|
||||
|
Reference in New Issue
Block a user