[Form] Fixed DateType/TimeType that were broken since 849fb29984
and 1c4a75a00a
This commit is contained in:
parent
9ca8709c47
commit
060d0f8821
@ -57,8 +57,8 @@ class DateType extends AbstractType
|
||||
|
||||
if ('single_text' === $options['widget']) {
|
||||
$builder->addViewTransformer(new DateTimeToLocalizedStringTransformer(
|
||||
null,
|
||||
null,
|
||||
$options['model_timezone'],
|
||||
$options['view_timezone'],
|
||||
$dateFormat,
|
||||
$timeFormat,
|
||||
$calendar,
|
||||
@ -105,7 +105,7 @@ class DateType extends AbstractType
|
||||
->add('month', $options['widget'], $monthOptions)
|
||||
->add('day', $options['widget'], $dayOptions)
|
||||
->addViewTransformer(new DateTimeToArrayTransformer(
|
||||
null, null, array('year', 'month', 'day')
|
||||
$options['model_timezone'], $options['view_timezone'], array('year', 'month', 'day')
|
||||
))
|
||||
->setAttribute('formatter', $formatter)
|
||||
;
|
||||
@ -113,15 +113,15 @@ class DateType extends AbstractType
|
||||
|
||||
if ('string' === $options['input']) {
|
||||
$builder->addModelTransformer(new ReversedTransformer(
|
||||
new DateTimeToStringTransformer(null, null, 'Y-m-d')
|
||||
new DateTimeToStringTransformer($options['model_timezone'], $options['model_timezone'], 'Y-m-d')
|
||||
));
|
||||
} elseif ('timestamp' === $options['input']) {
|
||||
$builder->addModelTransformer(new ReversedTransformer(
|
||||
new DateTimeToTimestampTransformer(null, null)
|
||||
new DateTimeToTimestampTransformer($options['model_timezone'], $options['model_timezone'])
|
||||
));
|
||||
} elseif ('array' === $options['input']) {
|
||||
$builder->addModelTransformer(new ReversedTransformer(
|
||||
new DateTimeToArrayTransformer(null, null, array('year', 'month', 'day'))
|
||||
new DateTimeToArrayTransformer($options['model_timezone'], $options['model_timezone'], array('year', 'month', 'day'))
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ class TimeType extends AbstractType
|
||||
}
|
||||
|
||||
if ('single_text' === $options['widget']) {
|
||||
$builder->addViewTransformer(new DateTimeToStringTransformer(null, null, $format));
|
||||
$builder->addViewTransformer(new DateTimeToStringTransformer($options['model_timezone'], $options['view_timezone'], $format));
|
||||
} else {
|
||||
$hourOptions = $minuteOptions = $secondOptions = array(
|
||||
'error_bubbling' => true,
|
||||
@ -109,20 +109,20 @@ class TimeType extends AbstractType
|
||||
$builder->add('second', $options['widget'], $secondOptions);
|
||||
}
|
||||
|
||||
$builder->addViewTransformer(new DateTimeToArrayTransformer(null, null, $parts, 'text' === $options['widget']));
|
||||
$builder->addViewTransformer(new DateTimeToArrayTransformer($options['model_timezone'], $options['view_timezone'], $parts, 'text' === $options['widget']));
|
||||
}
|
||||
|
||||
if ('string' === $options['input']) {
|
||||
$builder->addModelTransformer(new ReversedTransformer(
|
||||
new DateTimeToStringTransformer(null, null, 'H:i:s')
|
||||
new DateTimeToStringTransformer($options['model_timezone'], $options['model_timezone'], 'H:i:s')
|
||||
));
|
||||
} elseif ('timestamp' === $options['input']) {
|
||||
$builder->addModelTransformer(new ReversedTransformer(
|
||||
new DateTimeToTimestampTransformer(null, null)
|
||||
new DateTimeToTimestampTransformer($options['model_timezone'], $options['model_timezone'])
|
||||
));
|
||||
} elseif ('array' === $options['input']) {
|
||||
$builder->addModelTransformer(new ReversedTransformer(
|
||||
new DateTimeToArrayTransformer(null, null, $parts)
|
||||
new DateTimeToArrayTransformer($options['model_timezone'], $options['model_timezone'], $parts)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -380,93 +380,43 @@ class DateTypeTest extends TestCase
|
||||
));
|
||||
}
|
||||
|
||||
public function testSetDataWithDifferentNegativeUTCTimezoneDateTime()
|
||||
public function testSetDataWithNegativeTimezoneOffsetStringInput()
|
||||
{
|
||||
$form = $this->factory->create('date', null, array(
|
||||
'format' => \IntlDateFormatter::MEDIUM,
|
||||
'model_timezone' => 'America/New_York',
|
||||
'view_timezone' => 'Pacific/Tahiti',
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'America/New_York',
|
||||
'input' => 'string',
|
||||
'widget' => 'single_text',
|
||||
));
|
||||
|
||||
$form->setData('2010-06-02');
|
||||
|
||||
// 2010-06-02 00:00:00 UTC
|
||||
// 2010-06-01 20:00:00 UTC-4
|
||||
$this->assertEquals('01.06.2010', $form->getViewData());
|
||||
}
|
||||
|
||||
public function testSetDataWithDifferentTimezonesDateTime()
|
||||
public function testSetDataWithNegativeTimezoneOffsetDateTimeInput()
|
||||
{
|
||||
$form = $this->factory->create('date', null, array(
|
||||
'format' => \IntlDateFormatter::MEDIUM,
|
||||
'model_timezone' => 'America/New_York',
|
||||
'view_timezone' => 'Pacific/Tahiti',
|
||||
'model_timezone' => 'UTC',
|
||||
'view_timezone' => 'America/New_York',
|
||||
'input' => 'datetime',
|
||||
'widget' => 'single_text',
|
||||
));
|
||||
|
||||
$dateTime = new \DateTime('2010-06-02 America/New_York');
|
||||
$dateTime = new \DateTime('2010-06-02 UTC');
|
||||
|
||||
$form->setData($dateTime);
|
||||
|
||||
// 2010-06-02 00:00:00 UTC
|
||||
// 2010-06-01 20:00:00 UTC-4
|
||||
$this->assertDateTimeEquals($dateTime, $form->getData());
|
||||
$this->assertEquals('01.06.2010', $form->getViewData());
|
||||
}
|
||||
|
||||
public function testSetDataWithDifferentPositiveUTCTimezoneDateTime()
|
||||
{
|
||||
date_default_timezone_set('Pacific/Tahiti');
|
||||
|
||||
$form = $this->factory->create('date', null, array(
|
||||
'format' => \IntlDateFormatter::MEDIUM,
|
||||
'input' => 'datetime',
|
||||
'widget' => 'single_text',
|
||||
));
|
||||
|
||||
$dateTime = new \DateTime('2010-06-02 Australia/Melbourne');
|
||||
|
||||
$form->setData($dateTime);
|
||||
|
||||
$this->assertDateTimeEquals($dateTime, $form->getData());
|
||||
$this->assertEquals('02.06.2010', $form->getViewData());
|
||||
}
|
||||
|
||||
public function testSetDataWithSamePositiveUTCTimezoneDateTime()
|
||||
{
|
||||
date_default_timezone_set('Australia/Melbourne');
|
||||
|
||||
$form = $this->factory->create('date', null, array(
|
||||
'format' => \IntlDateFormatter::MEDIUM,
|
||||
'input' => 'datetime',
|
||||
'widget' => 'single_text',
|
||||
));
|
||||
|
||||
$dateTime = new \DateTime('2010-06-02 Australia/Melbourne');
|
||||
|
||||
$form->setData($dateTime);
|
||||
|
||||
$this->assertDateTimeEquals($dateTime, $form->getData());
|
||||
$this->assertEquals('02.06.2010', $form->getViewData());
|
||||
}
|
||||
|
||||
public function testSetDataWithSameNegativeUTCTimezoneDateTime()
|
||||
{
|
||||
date_default_timezone_set('America/New_York');
|
||||
|
||||
$form = $this->factory->create('date', null, array(
|
||||
'format' => \IntlDateFormatter::MEDIUM,
|
||||
'input' => 'datetime',
|
||||
'widget' => 'single_text',
|
||||
));
|
||||
|
||||
$dateTime = new \DateTime('2010-06-02 America/New_York');
|
||||
|
||||
$form->setData($dateTime);
|
||||
|
||||
$this->assertDateTimeEquals($dateTime, $form->getData());
|
||||
$this->assertEquals('02.06.2010', $form->getViewData());
|
||||
}
|
||||
|
||||
public function testYearsOption()
|
||||
{
|
||||
$form = $this->factory->create('date', null, array(
|
||||
|
Reference in New Issue
Block a user