Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Form] fixed date type format pattern regex #8198

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

Closed
wants to merge 1 commit into from
Closed
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
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function finishView(FormView $view, FormInterface $form, array $options)

// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,29 @@ public function testSubmitFromInputRawDifferentPattern()
$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.
Expand Down