8000 Drop support for model_timezone and view_timezone options in TimeType… · symfony/symfony@849fb29 · GitHub
[go: up one dir, main page]

Skip to content

Commit 849fb29

Browse files
jakzalfabpot
authored andcommitted
Drop support for model_timezone and view_timezone options in TimeType and DateType.
1 parent 009fd4d commit 849fb29

File tree

5 files changed

+39
-125
lines changed

5 files changed

+39
-125
lines changed

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CHANGELOG
77
* added "html5" option to Date, Time and DateTimeFormType to be able to
88
enable/disable HTML5 input date when widget option is "single_text"
99
* added "label_format" option with possible placeholders "%name%" and "%id%"
10+
* [BC BREAK] drop support for model_timezone and view_timezone options in TimeType and DateType
1011

1112
2.5.0
1213
------

src/Symfony/Component/Form/Extension/Core/Type/DateType.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
5757

5858
if ('single_text' === $options['widget']) {
5959
$builder->addViewTransformer(new DateTimeToLocalizedStringTransformer(
60-
$options['model_timezone'],
61-
$options['view_timezone'],
60+
'UTC',
61+
'UTC',
6262
$dateFormat,
6363
$timeFormat,
6464
$calendar,
@@ -105,23 +105,23 @@ public function buildForm(FormBuilderInterface $builder, array $options)
105105
->add('month', $options['widget'], $monthOptions)
106106
->add('day', $options['widget'], $dayOptions)
107107
->addViewTransformer(new DateTimeToArrayTransformer(
108-
$options['model_timezone'], $options['view_timezone'], array('year', 'month', 'day')
108+
'UTC', 'UTC', array('year', 'month', 'day')
109109
))
110110
->setAttribute('formatter', $formatter)
111111
;
112112
}
113113

114114
if ('string' === $options['input']) {
115115
$builder->addModelTransformer(new ReversedTransformer(
116-
new DateTimeToStringTransformer($options['model_timezone'], $options['model_timezone'], 'Y-m-d')
116+
new DateTimeToStringTransformer('UTC', 'UTC', 'Y-m-d')
117117
));
118118
} elseif ('timestamp' === $options['input']) {
119119
$builder->addModelTransformer(new ReversedTransformer(
120-
new DateTimeToTimestampTransformer($options['model_timezone'], $options['model_timezone'])
120+
new DateTimeToTimestampTransformer('UTC', 'UTC')
121121
));
122122
} elseif ('array' === $options['input']) {
123123
$builder->addModelTransformer(new ReversedTransformer(
124-
new DateTimeToArrayTransformer($options['model_timezone'], $options['model_timezone'], array('year', 'month', 'day'))
124+
new DateTimeToArrayTransformer('UTC', 'UTC', array('year', 'month', 'day'))
125125
));
126126
}
127127
}

‎< 341A !-- -->src/Symfony/Component/Form/Extension/Core/Type/TimeType.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
4848
}
4949

5050
if ('single_text' === $options['widget']) {
51-
$builder->addViewTransformer(new DateTimeToStringTransformer($options['model_timezone'], $options['view_timezone'], $format));
51+
$builder->addViewTransformer(new DateTimeToStringTransformer('UTC', 'UTC', $format));
5252
} else {
5353
$hourOptions = $minuteOptions = $secondOptions = array(
5454
'error_bubbling' => true,
@@ -109,20 +109,20 @@ public function buildForm(FormBuilderInterface $builder, array $options)
109109
$builder->add('second', $options['widget'], $secondOptions);
110110
}
111111

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

115115
if ('string' === $options['input']) {
116116
$builder->addModelTransformer(new ReversedTransformer(
117-
new DateTimeToStringTransformer($options['model_timezone'], $options['model_timezone'], 'H:i:s')
117+
new DateTimeToStringTransformer('UTC', 'UTC', 'H:i:s')
118118
));
119119
} elseif ('timestamp' === $options['input']) {
120120
$builder->addModelTransformer(new ReversedTransformer(
121-
new DateTimeToTimestampTransformer($options['model_timezone'], $options['model_timezone'])
121+
new DateTimeToTimestampTransformer('UTC', 'UTC')
122122
));
123123
} elseif ('array' === $options['input']) {
124124
$builder->addModelTransformer(new ReversedTransformer(
125-
new DateTimeToArrayTransformer($options['model_timezone'], $options['model_timezone'], $parts)
125+
new DateTimeToArrayTransformer('UTC', 'UTC', $parts)
126126
));
127127
}
128128
}
@@ -197,8 +197,6 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
197197
'input' => 'datetime',
198198
'with_minutes' => true,
199199
'with_seconds' => false,
200-
'model_timezone' => null,
201-
'view_timezone' => null,
202200
'empty_value' => $emptyValue, // deprecated
203201
'placeholder' => $placeholder,
204202
'html5' => true,

src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
class DateTypeTest extends TypeTestCase
1919
{
20+
private $defaultTimezone;
21+
2022
protected function setUp()
2123
{
2224
parent::setUp();
@@ -25,6 +27,13 @@ protected function setUp()
2527
IntlTestHelper::requireFullIntl($this);
2628

2729
\Locale::setDefault('de_AT');
30+
31+
$this->defaultTimezone = date_default_timezone_get();
32+
}
33+
34+
protected function tearDown()
35+
{
36+
date_default_timezone_set($this->defaultTimezone);
2837
}
2938

3039
/**
@@ -50,8 +59,6 @@ public function testInvalidInputOption()
5059
public function testSubmitFromSingleTextDateTimeWithDefaultFormat()
5160
{
5261
$form = $this->factory->create('date', null, array(
53-
'model_timezone' => 'UTC',
54-
'view_timezone' => 'UTC',
5562
'widget' => 'single_text',
5663
'input' => 'datetime',
5764
));
@@ -66,8 +73,6 @@ public function testSubmitFromSingleTextDateTime()
6673
{
6774
$form = $this->factory->create('date', null, array(
6875
'format' => \IntlDateFormatter::MEDIUM,
69-
'model_timezone' => 'UTC',
70-
'view_timezone' => 'UTC',
7176
'widget' => 'single_text',
7277
'input' => 'datetime',
7378
));
@@ -82,8 +87,6 @@ public function testSubmitFromSingleTextString()
8287
{
8388
$form = $this->factory->create('date', null, array(
8489
'format' => \IntlDateFormatter::MEDIUM,
85-
'model_timezone' => 'UTC',
86-
'view_timezone' => 'UTC',
8790
'widget' => 'single_text',
8891
'input' => 'string',
8992
));
@@ -98,8 +101,6 @@ public function testSubmitFromSingleTextTimestamp()
98101
{
99102
$form = $this->factory->create('date', null, array(
100103
'format' => \IntlDateFormatter::MEDIUM,
101-
'model_timezone' => 'UTC',
102-
'view_timezone' => 'UTC',
103104
'widget' => 'single_text',
104105
'input' => 'timestamp',
105106
));
@@ -116,8 +117,6 @@ public function testSubmitFromSingleTextRaw()
116117
{
117118
$form = $this->factory->create('date', null, array(
118119
'format' => \IntlDateFormatter::MEDIUM,
119-
'model_timezone' => 'UTC',
120-
'view_timezone' => 'UTC',
121120
'widget' => 'single_text',
122121
'input' => 'array',
123122
));
@@ -137,8 +136,6 @@ public function testSubmitFromSingleTextRaw()
137136
public function testSubmitFromText()
138137
{
139138
$form = $this->factory->create('date', null, array(
140-
'model_timezone' => 'UTC',
141-
'view_timezone' => 'UTC',
142139
'widget' => 'text',
143140
));
144141

@@ -159,8 +156,6 @@ public function testSubmitFromText()
159156
public function testSubmitFromChoice()
160157
{
161158
$form = $this->factory->create('date', null, array(
162-
'model_timezone' => 'UTC',
163-
'view_timezone' => 'UTC',
164159
'widget' => 'choice',
165160
));
166161

@@ -181,8 +176,6 @@ public function testSubmitFromChoice()
181176
public function testSubmitFromChoiceEmpty()
182177
{
183178
$form = $this->factory->create('date', null, array(
184-
'model_timezone' => 'UTC',
185-
'view_timezone' => 'UTC',
186179
'widget' => 'choice',
187180
'required' => false,
188181
));
@@ -202,8 +195,6 @@ public function testSubmitFromChoiceEmpty()
202195
public function testSubmitFromInputDateTimeDifferentPattern()
203196
{
204197
$form = $this->factory->create('date', null, array(
205-
'model_timezone' => 'UTC',
206-
'view_timezone' => 'UTC',
207198
'format' => 'MM*yyyy*dd',
208199
'widget' => 'single_text',
209200
'input' => 'datetime',
@@ -218,8 +209,6 @@ public function testSubmitFromInputDateTimeDifferentPattern()
218209
public function testSubmitFromInputStringDifferentPattern()
219210
{
220211
$form = $this->factory->create('date', null, array(
221-
'model_timezone' => 'UTC',
222-
'view_timezone' => 'UTC',
223212
'format' => 'MM*yyyy*dd',
224213
'widget' => 'single_text',
225214
'input' => 'string',
@@ -234,8 +223,6 @@ public function testSubmitFromInputStringDifferentPattern()
234223
public function testSubmitFromInputTimestampDifferentPattern()
235224
{
236225
$form = $this->factory->create('date', null, array(
237-
'model_timezone' => 'UTC',
238-
'view_timezone' => 'UTC',
239226
'format' => 'MM*yyyy*dd',
240227
'widget' => 'single_text',
241228
'input' => 'timestamp',
@@ -252,8 +239,6 @@ public function testSubmitFromInputTimestampDifferentPattern()
252239
public function testSubmitFromInputRawDifferentPattern()
253240
{
254241
$form = $this->factory->create('date', null, array(
255-
'model_timezone' => 'UTC',
256-
'view_timezone' => 'UTC',
257242
'format' => 'MM*yyyy*dd',
258243
'widget' => 'single_text',
259244
'input' => 'array',
@@ -370,27 +355,12 @@ public function testThrowExceptionIfDaysIsInvalid()
370355
));
371356
}
372357

373-
public function testSetDataWithDifferentTimezones()
358+
public function testSetDataWithDifferentTimezoneDateTime()
374359
{
375-
$form = $this->factory->create('date', null, array(
376-
'format' => \IntlDateFormatter::MEDIUM,
377-
'model_timezone' => 'America/New_York',
378-
'view_timezone' => 'Pacific/Tahiti',
379-
'input' => 'string',
380-
'widget' => 'single_text',
381-
));
360+
date_default_timezone_set('Pacific/Tahiti');
382361

383-
$form->setData('2010-06-02');
384-
385-
$this->assertEquals('01.06.2010', $form->getViewData());
386-
}
387-
388-
public function testSetDataWithDifferentTimezonesDateTime()
389-
{
390362
$form = $this->factory->create('date', null, array(
391363
'format' => \IntlDateFormatter::MEDIUM,
392-
'model_timezone' => 'America/New_York',
393-
'view_timezone' => 'Pacific/Tahiti',
394364
'input' => 'datetime',
395365
'widget' => 'single_text',
396366
));
@@ -400,7 +370,7 @@ public function testSetDataWithDifferentTimezonesDateTime()
400370
$form->setData($dateTime);
401371

402372
$this->assertDateTimeEquals($dateTime, $form->getData());
403-
$this->assertEquals('01.06.2010', $form->getViewData());
373+
$this->assertEquals('02.06.2010', $form->getViewData());
404374
}
405375

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

497467
$form = $this->factory->create('date', null, array(
498-
'model_timezone' => 'UTC',
499-
'view_timezone' => 'UTC',
500468
'widget' => 'single_text',
501469
));
502470

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

512480
$form = $this->factory->create('date', null, array(
513-
'model_timezone' => 'UTC',
514-
'view_timezone' => 'UTC',
515481
'widget' => 'choice',
516482
));
517483

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

531497
$form = $this->factory->create('date', null, array(
532-
'model_timezone' => 'UTC',
533-
'view_timezone' => 'UTC',
534498
'widget' => 'choice',
535499
));
536500

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

550514
$form = $this->factory->create('date', null, array(
551-
'model_timezone' => 'UTC',
552-
'view_timezone' => 'UTC',
553515
'widget' => 'choice',
554516
));
555517

0 commit comments

Comments
 (0)
0