Change datetime input to datetime-local

This commit is contained in:
Pierre du Plessis 2017-10-02 14:38:17 +02:00
parent f7d9701cdf
commit 802c67c324
4 changed files with 10 additions and 15 deletions

View File

@ -34,17 +34,12 @@ class DateTimeType extends AbstractType
/** /**
* This is not quite the HTML5 format yet, because ICU lacks the * This is not quite the HTML5 format yet, because ICU lacks the
* capability of parsing and generating RFC 3339 dates, which * capability of parsing and generating RFC 3339 dates.
* are like the below pattern but with a timezone suffix. The
* timezone suffix is.
*
* * "Z" for UTC
* * "(-|+)HH:mm" for other timezones (note the colon!)
* *
* For more information see: * For more information see:
* *
* http://userguide.icu-project.org/formatparse/datetime#TOC-Date-Time-Format-Syntax * http://userguide.icu-project.org/formatparse/datetime#TOC-Date-Time-Format-Syntax
* http://www.w3.org/TR/html-markup/input.datetime.html * https://www.w3.org/TR/html5/sec-forms.html#local-date-and-time-state-typedatetimelocal
* http://tools.ietf.org/html/rfc3339 * http://tools.ietf.org/html/rfc3339
* *
* An ICU ticket was created: * An ICU ticket was created:
@ -54,7 +49,7 @@ class DateTimeType extends AbstractType
* yet. To temporarily circumvent this issue, DateTimeToRfc3339Transformer * yet. To temporarily circumvent this issue, DateTimeToRfc3339Transformer
* is used when the format matches this constant. * is used when the format matches this constant.
*/ */
const HTML5_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"; const HTML5_FORMAT = "yyyy-MM-dd'T'HH:mm:ss";
private static $acceptedFormats = array( private static $acceptedFormats = array(
\IntlDateFormatter::FULL, \IntlDateFormatter::FULL,
@ -192,7 +187,7 @@ class DateTimeType extends AbstractType
// * the format matches the one expected by HTML5 // * the format matches the one expected by HTML5
// * the html5 is set to true // * the html5 is set to true
if ($options['html5'] && 'single_text' === $options['widget'] && self::HTML5_FORMAT === $options['format']) { if ($options['html5'] && 'single_text' === $options['widget'] && self::HTML5_FORMAT === $options['format']) {
$view->vars['type'] = 'datetime'; $view->vars['type'] = 'datetime-local';
} }
} }

View File

@ -1525,7 +1525,7 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
$this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')), $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
'/input '/input
[@type="datetime"] [@type="datetime-local"]
[@name="name"] [@name="name"]
[@class="my&class form-control"] [@class="my&class form-control"]
[@value="2011-02-03T04:05:06Z"] [@value="2011-02-03T04:05:06Z"]
@ -1546,7 +1546,7 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
$this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')), $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
'/input '/input
[@type="datetime"] [@type="datetime-local"]
[@name="name"] [@name="name"]
[@class="my&class form-control"] [@class="my&class form-control"]
[@value="2011-02-03T04:05:06Z"] [@value="2011-02-03T04:05:06Z"]

View File

@ -1426,7 +1426,7 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase
$this->assertWidgetMatchesXpath($form->createView(), array(), $this->assertWidgetMatchesXpath($form->createView(), array(),
'/input '/input
[@type="datetime"] [@type="datetime-local"]
[@name="name"] [@name="name"]
[@value="2011-02-03T04:05:06Z"] [@value="2011-02-03T04:05:06Z"]
' '
@ -1446,7 +1446,7 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase
$this->assertWidgetMatchesXpath($form->createView(), array(), $this->assertWidgetMatchesXpath($form->createView(), array(),
'/input '/input
[@type="datetime"] [@type="datetime-local"]
[@name="name"] [@name="name"]
[@value="2011-02-03T04:05:06Z"] [@value="2011-02-03T04:05:06Z"]
' '

View File

@ -283,7 +283,7 @@ class DateTimeTypeTest extends BaseTypeTest
)) ))
->createView(); ->createView();
$this->assertEquals('datetime', $view->vars['type']); $this->assertEquals('datetime-local', $view->vars['type']);
} }
public function testPassDefaultPlaceholderToViewIfNotRequired() public function testPassDefaultPlaceholderToViewIfNotRequired()
@ -433,7 +433,7 @@ class DateTimeTypeTest extends BaseTypeTest
)) ))
->createView(); ->createView();
$this->assertSame('datetime', $view->vars['type']); $this->assertSame('datetime-local', $view->vars['type']);
} }
public function testDontPassHtml5TypeIfHtml5NotAllowed() public function testDontPassHtml5TypeIfHtml5NotAllowed()