fixed date type format pattern regex
This commit is contained in:
parent
24a07fbab8
commit
6b715136c8
|
@ -144,7 +144,7 @@ class DateType extends AbstractType
|
|||
|
||||
// set right order with respect to locale (e.g.: de_DE=dd.MM.yy; en_US=M/d/yy)
|
||||
// lookup various formats at http://userguide.icu-project.org/formatparse/datetime
|
||||
if (preg_match('/^([yMd]+).+([yMd]+).+([yMd]+)$/', $pattern)) {
|
||||
if (preg_match('/^([yMd]+)[^yMd]*([yMd]+)[^yMd]*([yMd]+)$/', $pattern)) {
|
||||
$pattern = preg_replace(array('/y+/', '/M+/', '/d+/'), array('{{ year }}', '{{ month }}', '{{ day }}'), $pattern);
|
||||
} else {
|
||||
// default fallback
|
||||
|
|
|
@ -267,6 +267,29 @@ class DateTypeTest extends LocalizedTestCase
|
|||
$this->assertEquals('06*2010*02', $form->getViewData());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideDateFormats
|
||||
*/
|
||||
public function testDatePatternWithFormatOption($format, $pattern)
|
||||
{
|
||||
$form = $this->factory->create('date', null, array(
|
||||
'format' => $format,
|
||||
));
|
||||
|
||||
$view = $form->createView();
|
||||
|
||||
$this->assertEquals($pattern, $view->vars['date_pattern']);
|
||||
}
|
||||
|
||||
public function provideDateFormats()
|
||||
{
|
||||
return array(
|
||||
array('dMy', '{{ day }}{{ month }}{{ year }}'),
|
||||
array('d-M-yyyy', '{{ day }}-{{ month }}-{{ year }}'),
|
||||
array('M d y', '{{ month }} {{ day }} {{ year }}'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test is to check that the strings '0', '1', '2', '3' are no accepted
|
||||
* as valid IntlDateFormatter constants for FULL, LONG, MEDIUM or SHORT respectively.
|
||||
|
|
Reference in New Issue