8000 [Form] Fixed display of [Date]TimeType when displayed as "single_text" and "with_seconds" is false by webmozart · Pull Request #3860 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] Fixed display of [Date]TimeType when displayed as "single_text" and "with_seconds" is false #3860

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

Merged
merged 1 commit into from
Apr 10, 2012
Merged
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
8000
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Form] Fixed display of DateTimeType and TimeType when displayed as "…
…single_text" and "with_seconds" is false
  • Loading branch information
webmozart committed Apr 10, 2012
commit 004c873c74d9c36d1a0810580e09dcb99250eaee
2 changes: 2 additions & 0 deletions CHANGELOG-2.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c
in class Form now throw an exception if the form is already bound
* fields of constrained classes without a NotBlank or NotNull constraint are
set to not required now, as stated in the docs
* fixed TimeType and DateTimeType to not display seconds when "widget" is
"single_text" unless "with_seconds" is set to true

### HttpFoundation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function buildForm(FormBuilder $builder, array $options)
$parts = array('year', 'month', 'day', 'hour', 'minute');
$timeParts = array('hour', 'minute');

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

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

if ('string' === $options['input']) {
$builder->appendNormTransformer(new ReversedTransformer(
new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'], $format)
new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'])
));
} elseif ('timestamp' === $options['input']) {
$builder->appendNormTransformer(new ReversedTransformer(
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Form/Extension/Core/Type/TimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TimeType extends AbstractType
public function buildForm(FormBuilder $builder, array $options)
{
$parts = array('hour', 'minute');
$format = 'H:i:00';
$format = 'H:i';
if ($options['with_seconds']) {
$format = 'H:i:s';
$parts[] = 'second';
Expand Down Expand Up @@ -108,7 +108,7 @@ public function buildForm(FormBuilder $builder, array $options)
if ('string' === $options['input']) {
$builder->appendNormTransformer(new ReversedTransformer(
new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'], $format)
new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'], 'H:i:s')
));
} elseif ('timestamp' === $options['input']) {
$builder->appendNormTransformer(new ReversedTransformer(
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/Form/Tests/AbstractLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ public function testDateTimeSingleText()
[@type="text"]
[@id="name_time"]
[@name="name[time]"]
[@value="04:05:00"]
[@value="04:05"]
]
'
);
Expand All @@ -967,7 +967,7 @@ public function testDateTimeWithWidgetSingleText()
'/input
[@type="text"]
[@name="name"]
[@value="2011-02-03 04:05:00"]
[@value="2011-02-03 04:05"]
'
);
}
Expand All @@ -985,7 +985,7 @@ public function testDateTimeWithWidgetSingleTextIgnoreDateAndTimeWidgets()
'/input
[@type="text"]
[@name="name"]
[@value="2011-02-03 04:05:00"]
[@value="2011-02-03 04:05"]
'
);
}
Expand Down Expand Up @@ -1583,7 +1583,7 @@ public function testTimeSingleText()
'/input
[@type="text"]
[@name="name"]
[@value="04:05:00"]
[@value="04:05"]
'
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function testSubmit_differentTimezonesDateTime()
$outputTime->setTimezone(new \DateTimeZone('America/New_York'));

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

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

$this->assertEquals('2010-06-02 03:04:00', $form->getData());
$this->assertEquals('2010-06-02 03:04:00', $form->getClientData());
$this->assertEquals('2010-06-02 03:04', $form->getClientData());
}

public function testSubmit_stringSingleText_withSeconds()
{
$form = $this->factory->create('datetime', null, array(
'data_timezone' => 'UTC',
'user_timezone' => 'UTC',
'input' => 'string',
'widget' => 'single_text',
'with_seconds' => true,
));

$form->bind('2010-06-02 03:04:05');

$this->assertEquals('2010-06-02 03:04:05', $form->getData());
$this->assertEquals('2010-06-02 03:04:05', $form->getClientData());
}

public function testSubmit_differentPattern()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function testSubmit_datetimeSingleText()
$form->bind('03:04:05');

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

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

$this->assertEquals($data, $form->getData());
$this->assertEquals('03:04:00', $form->getClientData());
$this->assertEquals('03:04', $form->getClientData());
}

public function testSubmit_arraySingleTextWithSeconds()
Expand Down Expand Up @@ -164,7 +164,7 @@ public function testSubmit_stringSingleText()
$form->bind('03:04:05');

$this->assertEquals('03:04:00', $form->getData());
$this->assertEquals('03:04:00', $form->getClientData());
$this->assertEquals('03:04', $form->getClientData());
}

public function testSetData_withSeconds()
Expand Down
0