8000 merged branch bschussek/issue3278 (PR #3860) · symfony/symfony@48abdaf · GitHub
[go: up one dir, main page]

Skip to content

Commit 48abdaf

Browse files
committed
merged branch bschussek/issue3278 (PR #3860)
Commits ------- 004c873 [Form] Fixed display of DateTimeType and TimeType when displayed as "single_text" and "with_seconds" is false Discussion ---------- [Form] Fixed display of [Date]TimeType when displayed as "single_text" and "with_seconds" is false Bug fix: yes Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes Fixes the following tickets: #3278 Todo: - ![Travis Build Status](https://secure.travis-ci.org/bschussek/symfony.png?branch=issue3278)
2 parents 837960f + 004c873 commit 48abdaf

File tree

6 files changed

+31
-13
lines changed

6 files changed

+31
-13
lines changed

CHANGELOG-2.1.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c
263263
in class Form now throw an exception if the form is already bound
264264
* fields of constrained classes without a NotBlank or NotNull constraint are
265265
set to not required now, as stated in the docs
266+
* fixed TimeType and DateTimeType to not display seconds when "widget" is
267+
"single_text" unless "with_seconds" is set to true
266268

267269
### HttpFoundation
268270

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function buildForm(FormBuilder $builder, array $options)
3232
$parts = array('year', 'month', 'day', 'hour', 'minute');
3333
$timeParts = array('hour', 'minute');
3434

35-
$format = 'Y-m-d H:i:00';
35+
$format = 'Y-m-d H:i';
3636
if ($options['with_seconds']) {
3737
$format = 'Y-m-d H:i:s';
3838

@@ -102,7 +102,7 @@ public function buildForm(FormBuilder $builder, array $options)
102102

103103
if ('string' === $options['input']) {
104104
$builder->appendNormTransformer(new ReversedTransformer(
105-
new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'], $format)
105+
new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'])
106106
));
107107
} elseif ('timestamp' === $options['input']) {
108108
$builder->appendNormTransformer(new ReversedTransformer(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class TimeType extends AbstractType
2929
public function buildForm(FormBuilder $builder, array $options)
3030
{
3131
$parts = array('hour', 'minute');
32-
$format = 'H:i:00';
32+
$format = 'H:i';
3333
if ($options['with_seconds']) {
3434
$format = 'H:i:s';
3535
$parts[] = 'second';
@@ -108,7 +108,7 @@ public function buildForm(FormBuilder $builder, array $options)
108108

109109
if ('string' === $options['input']) {
110110
$builder->appendNormTransformer(new ReversedTransformer(
111-
new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'], $format)
111+
new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'], 'H:i:s')
112112
));
113113
} elseif ('timestamp' === $options['input']) {
114114
$builder->appendNormTransformer(new ReversedTransformer(

src/Symfony/Component/Form/Tests/AbstractLayoutTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ public function testDateTimeSingleText()
950950
[@type="text"]
951951
[@id="name_time"]
952952
[@name="name[time]"]
953-
[@value="04:05:00"]
953+
[@value="04:05"]
954954
]
955955
'
956956
);
@@ -967,7 +967,7 @@ public function testDateTimeWithWidgetSingleText()
967967
'/input
968968
[@type="text"]
969969
[@name="name"]
970-
[@value="2011-02-03 04:05:00"]
970+
[@value="2011-02-03 04:05"]
971971
'
972972
);
973973
}
@@ -985,7 +985,7 @@ public function testDateTimeWithWidgetSingleTextIgnoreDateAndTimeWidgets()
985985
'/input
986986
[@type="text"]
987987
[@name="name"]
988-
[@value="2011-02-03 04:05:00"]
988+
[@value="2011-02-03 04:05"]
989989
'
990990
);
991991
}
@@ -1583,7 +1583,7 @@ public function testTimeSingleText()
15831583
'/input
15841584
[@type="text"]
15851585
[@name="name"]
1586-
[@value="04:05:00"]
1586+
[@value="04:05"]
15871587
'
15881588
);
15891589
}

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public function testSubmit_differentTimezonesDateTime()
173173
$outputTime->setTimezone(new \DateTimeZone('America/New_York'));
174174

175175
$this->assertDateTimeEquals($outputTime, $form->getData());
176-
$this->assertEquals('2010-06-02 03:04:00', $form->getClientData());
176+
$this->assertEquals('2010-06-02 03:04', $form->getClientData());
177177
}
178178

179179
public function testSubmit_stringSingleText()
@@ -188,7 +188,23 @@ public function testSubmit_stringSingleText()
188188
$form->bind('2010-06-02 03:04:05');
189189

190190
$this->assertEquals('2010-06-02 03:04:00', $form->getData());
191-
$this->assertEquals('2010-06-02 03:04:00', $form->getClientData());
191+
$this->assertEquals('2010-06-02 03:04', $form->getClientData());
192+
}
193+
194+
public function testSubmit_stringSingleText_withSeconds()
195+
{
196+
$form = $this->factory->create('datetime', null, array(
197+
'data_timezone' => 'UTC',
198+
'user_timezone' => 'UTC',
199+
'input' => 'string',
200+
'widget' => 'single_text',
201+
'with_seconds' => true,
202+
));
203+
204+
$form->bind('2010-06-02 03:04:05');
205+
206+
$this->assertEquals('2010-06-02 03:04:05', $form->getData());
207+
$this->assertEquals('2010-06-02 03:04:05', $form->getClientData());
192208
}
193209

194210
public function testSubmit_differentPattern()

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function testSubmit_datetimeSingleText()
107107
$form->bind('03:04:05');
108108

109109
$this->assertEquals(new \DateTime('03:04:00 UTC'), $form->getData());
110-
$this->assertEquals('03:04:00', $form->getClientData());
110+
$this->assertEquals('03:04', $form->getClientData());
111111
}
112112

113113
public function testSubmit_arraySingleText()
@@ -127,7 +127,7 @@ public function testSubmit_arraySingleText()
127127
$form->bind('03:04');
128128

129129
$this->assertEquals($data, $form->getData());
130-
$this->assertEquals('03:04:00', $form->getClientData());
130+
$this->assertEquals('03:04', $form->getClientData());
131131
}
132132

133133
public function testSubmit_arraySingleTextWithSeconds()
@@ -164,7 +164,7 @@ public function testSubmit_stringSingleText()
164164
$form->bind('03:04:05');
165165

166166
$this->assertEquals('03:04:00', $form->getData());
167-
$this->assertEquals('03:04:00', $form->getClientData());
167+
$this->assertEquals('03:04', $form->getClientData());
168168
}
169169

170170
public function testSetData_withSeconds()

0 commit comments

Comments
 (0)
0