8000 [Form] Remove timezone options from DateType and TimeType by jakzal · Pull Request #12404 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] Remove timezone options from DateType and TimeType #12404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Component/Form/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CHANGELOG
* added "html5" option to Date, Time and DateTimeFormType to be able to
enable/disable HTML5 input date when widget option is "single_text"
* added "label_format" option with possible placeholders "%name%" and "%id%"
* [BC BREAK] drop support for model_timezone and view_timezone options in TimeType and DateType

2.5.0
------
Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Component/Form/Extension/Core/Type/DateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)

if ('single_text' === $options['widget']) {
$builder->addViewTransformer(new DateTimeToLocalizedStringTransformer(
$options['model_timezone'],
$options['view_timezone'],
'UTC',
'UTC',
$dateFormat,
$timeFormat,
$calendar,
Expand Down Expand Up @@ -105,23 +105,23 @@ public function buildForm(FormBuilderInterface $builder, array $options)
->add('month', $options['widget'], $monthOptions)
->add('day', $options['widget'], $dayOptions)
->addViewTransformer(new DateTimeToArrayTransformer(
$options['model_timezone'], $options['view_timezone'], array('year', 'month', 'day')
'UTC', 'UTC', array('year', 'month', 'day')
))
->setAttribute('formatter', $formatter)
;
}

if ('string' === $options['input']) {
$builder->addModelTransformer(new ReversedTransformer(
new DateTimeToStringTransformer($options['model_timezone'], $options['model_timezone'], 'Y-m-d')
new DateTimeToStringTransformer('UTC', 'UTC', 'Y-m-d')
));
} elseif ('timestamp' === $options['input']) {
$builder->addModelTransformer(new ReversedTransformer(
new DateTimeToTimestampTransformer($options['model_timezone'], $options['model_timezone'])
new DateTimeToTimestampTransformer('UTC', 'UTC')
));
} elseif ('array' === $options['input']) {
$builder->addModelTransformer(new ReversedTransformer(
new DateTimeToArrayTransformer($options['model_timezone'], $options['model_timezone'], array('year', 'month', 'day'))
new DateTimeToArrayTransformer('UTC', 'UTC', array('year', 'month', 'day'))
));
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/Symfony/Component/Form/Extension/Core/Type/TimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
}

if ('single_text' === $options['widget']) {
$builder->addViewTransformer(new DateTimeToStringTransformer($options['model_timezone'], $options['view_timezone'], $format));
$builder->addViewTransformer(new DateTimeToStringTransformer('UTC' 8000 , 'UTC', $format));
} else {
$hourOptions = $minuteOptions = $secondOptions = array(
'error_bubbling' => true,
Expand Down Expand Up @@ -109,20 +109,20 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$builder->add('second', $options['widget'], $secondOptions);
}

$builder->addViewTransformer(new DateTimeToArrayTransformer($options['model_timezone'], $options['view_timezone'], $parts, 'text' === $options['widget']));
$builder->addViewTransformer(new DateTimeToArrayTransformer('UTC', 'UTC', $parts, 'text' === $options['widget']));
}

if ('string' === $options['input']) {
$builder->addModelTransformer(new ReversedTransformer(
new DateTimeToStringTransformer($options['model_timezone'], $options['model_timezone'], 'H:i:s')
new DateTimeToStringTransformer('UTC', 'UTC', 'H:i:s')
));
} elseif ('timestamp' === $options['input']) {
$builder->addModelTransformer(new ReversedTransformer(
new DateTimeToTimestampTransformer($options['model_timezone'], $options['model_timezone'])
new DateTimeToTimestampTransformer('UTC', 'UTC')
));
} elseif ('array' === $options['input']) {
$builder->addModelTransformer(new ReversedTransformer(
new DateTimeToArrayTransformer($options['model_timezone'], $options['model_timezone'], $parts)
new DateTimeToArrayTransformer('UTC', 'UTC', $parts)
));
}
}
Expand Down Expand Up @@ -197,8 +197,6 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
'input' => 'datetime',
'with_minutes' => true,
'with_seconds' => false,
'model_timezone' => null,
'view_timezone' => null,
'empty_value' => $emptyValue, // deprecated
'placeholder' => $placeholder,
'html5' => true,
8000 Expand Down
628C
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

class DateTypeTest extends TypeTestCase
{
private $defaultTimezone;

protected function setUp()
{
parent::setUp();
Expand All @@ -25,6 +27,13 @@ protected function setUp()
IntlTestHelper::requireFullIntl($this);

\Locale::setDefault('de_AT');

$this->defaultTimezone = date_default_timezone_get();
}

protected function tearDown()
{
date_default_timezone_set($this->defaultTimezone);
}

/**
Expand All @@ -50,8 +59,6 @@ public function testInvalidInputOption()
public function testSubmitFromSingleTextDateTimeWithDefaultFormat()
{
$form = $this->factory->create('date', null, array(
'model_timezone' => 'UTC',
'view_timezone' => 'UTC',
'widget' => 'single_text',
'input' => 'datetime',
));
Expand All @@ -66,8 +73,6 @@ public function testSubmitFromSingleTextDateTime()
{
$form = $this->factory->create('date', null, array(
'format' => \IntlDateFormatter::MEDIUM,
'model_timezone' => 'UTC',
'view_timezone' => 'UTC',
'widget' => 'single_text',
'input' => 'datetime',
));
Expand All @@ -82,8 +87,6 @@ public function testSubmitFromSingleTextString()
{
$form = $this->factory->create('date', null, array(
'format' => \IntlDateFormatter::MEDIUM,
'model_timezone' => 'UTC',
'view_timezone' => 'UTC',
'widget' => 'single_text',
'input' => 'string',
));
Expand All @@ -98,8 +101,6 @@ public function testSubmitFromSingleTextTimestamp()
{
$form = $this->factory->create('date', null, array(
'format' => \IntlDateFormatter::MEDIUM,
'model_timezone' => 'UTC',
'view_timezone' => 'UTC',
'widget' => 'single_text',
'input' => 'timestamp',
));
Expand All @@ -116,8 +117,6 @@ public function testSubmitFromSingleTextRaw()
{
$form = $this->factory->create('date', null, array(
'format' => \IntlDateFormatter::MEDIUM,
'model_timezone' => 'UTC',
'view_timezone' => 'UTC',
'widget' => 'single_text',
'input' => 'array',
));
Expand All @@ -137,8 +136,6 @@ public function testSubmitFromSingleTextRaw()
public function testSubmitFromText()
{
$form = $this->factory->create('date', null, array(
'model_timezone' => 'UTC',
'view_timezone' => 'UTC',
'widget' => 'text',
));

Expand All @@ -159,8 +156,6 @@ public function testSubmitFromText()
public function testSubmitFromChoice()
{
$form = $this->factory->create('date', null, array(
'model_timezone' => 'UTC',
'view_timezone' => 'UTC',
'widget' => 'choice',
));

Expand All @@ -181,8 +176,6 @@ public function testSubmitFromChoice()
public function testSubmitFromChoiceEmpty()
{
$form = $this->factory->create('date', null, array(
'model_timezone' => 'UTC',
'view_timezone' => 'UTC',
'widget' => 'choice',
'required' => false,
));
Expand All @@ -202,8 +195,6 @@ public function testSubmitFromChoiceEmpty()
public function testSubmitFromInputDateTimeDifferentPattern()
{
$form = $this->factory->create('date', null, array(
'model_timezone' => 'UTC',
'view_timezone' => 'UTC',
'format' => 'MM*yyyy*dd',
'widget' => 'single_text',
'input' => 'datetime',
Expand All @@ -218,8 +209,6 @@ public function testSubmitFromInputDateTimeDifferentPattern()
public function testSubmitFromInputStringDifferentPattern()
{
$form = $this->factory->create('date', null, array(
'model_timezone' => 'UTC',
'view_timezone' => 'UTC',
'format' => 'MM*yyyy*dd',
'widget' => 'single_text',
'input' => 'string',
Expand All @@ -234,8 +223,6 @@ public function testSubmitFromInputStringDifferentPattern()
public function testSubmitFromInputTimestampDifferentPattern()
{
$form = $this->factory->create('date', null, array(
'model_timezone' => 'UTC',
'view_timezone' => 'UTC',
'format' => 'MM*yyyy*dd',
'widget' => 'single_text',
'input' => 'timestamp',
Expand All @@ -252,8 +239,6 @@ public function testSubmitFromInputTimestampDifferentPattern()
public function testSubmitFromInputRawDifferentPattern()
{
$form = $this->factory->create('date', null, array(
'model_timezone' => 'UTC',
'view_timezone' => 'UTC',
'format' => 'MM*yyyy*dd',
'widget' => 'single_text',
'input' => 'array',
Expand Down Expand Up @@ -370,27 +355,12 @@ public function testThrowExceptionIfDaysIsInvalid()
));
}

public function testSetDataWithDifferentTimezones()
public function testSetDataWithDifferentTimezoneDateTime()
{
$form = $this->factory->create('date', null, array(
'format' => \IntlDateFormatter::MEDIUM,
'model_timezone' => 'America/New_York',
'view_timezone' => 'Pacific/Tahiti',
'input' => 'string',
'widget' => 'single_text',
));
date_default_timezone_set('Pacific/Tahiti');

$form->setData('2010-06-02');

$this->assertEquals('01.06.2010', $form->getViewData());
}

public function testSetDataWithDifferentTimezonesDateTime()
{
$form = $this->factory->create('date', null, array(
'format' => \IntlDateFormatter::MEDIUM,
'model_timezone' => 'America/New_York',
'view_timezone' => 'Pacific/Tahiti',
'input' => 'datetime',
'widget' => 'single_text',
));
Expand All @@ -400,7 +370,7 @@ public function testSetDataWithDifferentTimezonesDateTime()
$form->setData($dateTime);

$this->assertDateTimeEquals($dateTime, $form->getData());
$this->assertEquals('01.06.2010', $form->getViewData());
$this->assertEquals('02.06.2010', $form->getViewData());
}

public function testYearsOption()
Expand Down Expand Up @@ -495,8 +465,6 @@ public function testIsPartiallyFilledReturnsFalseIfSingleText()
$this->markTestIncomplete('Needs to be reimplemented using validators');

$form = $this->factory->create('date', null, array(
'model_timezone' => 'UTC',
'view_timezone' => 'UTC',
'widget' => 'single_text',
));

Expand All @@ -510,8 +478,6 @@ public function testIsPartiallyFilledReturnsFalseIfChoiceAndCompletelyEmpty()
$this->markTestIncomplete('Needs to be reimplemented using validators');

$form = $this->factory->create('date', null, array(
'model_timezone' => 'UTC',
'view_timezone' => 'UTC',
'widget' => 'choice',
));

Expand All @@ -529,8 +495,6 @@ public function testIsPartiallyFilledReturnsFalseIfChoiceAndCompletelyFilled()
$this->markTestIncomplete('Needs to be reimplemented using validators');

$form = $this->factory->create('date', null, array(
'model_timezone' => 'UTC',
'view_timezone' => 'UTC',
'widget' => 'choice',
));

Expand All @@ -548,8 +512,6 @@ public function testIsPartiallyFilledReturnsTrueIfChoiceAndDayEmpty()
$this->markTestIncomplete('Needs to be reimplemented using validators');

$form = $this->factory->create('date', null, array(
'model_timezone' => 'UTC',
'view_timezone' => 'UTC',
'widget' => 'choice',
));

Expand Down
Loading
0