Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/3746'
Browse files Browse the repository at this point in the history
Close #3746
Fixes #3694
  • Loading branch information
weierophinney committed Feb 19, 2013
2 parents 3cee776 + 433a9fc commit 346b337
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 17 deletions.
20 changes: 11 additions & 9 deletions library/Zend/Form/View/Helper/FormDateTimeSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ public function getPattern()
{
if ($this->pattern === null) {
$intl = new IntlDateFormatter($this->getLocale(), $this->dateType, $this->timeType);
$this->pattern = $intl->getPattern();
// remove time zone format character
$pattern = rtrim($intl->getPattern(), ' z');
$this->pattern = $pattern;
}

return $this->pattern;
Expand All @@ -182,24 +184,24 @@ public function getPattern()
protected function parsePattern($renderDelimiters = true)
{
$pattern = $this->getPattern();
$pregResult = preg_split('/([ -,.:\/]+)/', $pattern, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$pregResult = preg_split("/([ -,.:\/]*'.*?'[ -,.:\/]*)|([ -,.:\/]+)/", $pattern, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);

$result = array();
foreach ($pregResult as $value) {
if (stripos($value, 'd') !== false) {
if (stripos($value, "'") === false && stripos($value, 'd') !== false) {
$result['day'] = $value;
} elseif (strpos($value, 'M') !== false) {
} elseif (stripos($value, "'") === false && strpos($value, 'M') !== false) {
$result['month'] = $value;
} elseif (stripos($value, 'y') !== false) {
} elseif (stripos($value, "'") === false && stripos($value, 'y') !== false) {
$result['year'] = $value;
} elseif (stripos($value, 'h') !== false) {
} elseif (stripos($value, "'") === false && stripos($value, 'h') !== false) {
$result['hour'] = $value;
} elseif (stripos($value, 'm') !== false) {
} elseif (stripos($value, "'") === false && stripos($value, 'm') !== false) {
$result['minute'] = $value;
} elseif (strpos($value, 's') !== false) {
} elseif (stripos($value, "'") === false && strpos($value, 's') !== false) {
$result['second'] = $value;
} elseif ($renderDelimiters) {
$result[] = $value;
$result[] = str_replace("'", '', $value);
}
}

Expand Down
10 changes: 5 additions & 5 deletions library/Zend/Form/View/Helper/FormMonthSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,18 @@ public function getPattern()
protected function parsePattern($renderDelimiters = true)
{
$pattern = $this->getPattern();
$pregResult = preg_split('/([ -,.\/]+)/', $pattern, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$pregResult = preg_split("/([ -,.\/]*(?:'[a-zA-Z]+')*[ -,.\/]+)/", $pattern, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);

$result = array();
foreach ($pregResult as $value) {
if (stripos($value, 'd') !== false) {
if (stripos($value, "'") === false && stripos($value, 'd') !== false) {
$result['day'] = $value;
} elseif (stripos($value, 'm') !== false) {
} elseif (stripos($value, "'") === false && stripos($value, 'm') !== false) {
$result['month'] = $value;
} elseif (stripos($value, 'y') !== false) {
} elseif (stripos($value, "'") === false && stripos($value, 'y') !== false) {
$result['year'] = $value;
} elseif ($renderDelimiters) {
$result[] = $value;
$result[] = str_replace("'", '', $value);
}
}

Expand Down
13 changes: 12 additions & 1 deletion tests/ZendTest/Form/View/Helper/FormDateSelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,22 @@ public function testCanDisableDelimiters()
$element->setShouldRenderDelimiters(false);
$markup = $this->helper->render($element);

// If it contains wo consecutive selects this means that no delimiters
// If it contains two consecutive selects this means that no delimiters
// are inserted
$this->assertContains('</select><select', $markup);
}

public function testCanRenderTextDelimiters()
{
$element = new DateSelect('foo');
$element->setShouldCreateEmptyOption(true);
$element->setShouldRenderDelimiters(true);
$markup = $this->helper->__invoke($element, \IntlDateFormatter::LONG, 'pt_BR');

// pattern === "d 'de' MMMM 'de' y"
$this->assertStringMatchesFormat('%a de %a de %a', $markup);
}

public function testInvokeProxiesToRender()
{
$element = new DateSelect('foo');
Expand Down
14 changes: 13 additions & 1 deletion tests/ZendTest/Form/View/Helper/FormDateTimeSelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,23 @@ public function testCanDisableDelimiters()
$element->setShouldRenderDelimiters(false);
$markup = $this->helper->render($element);

// If it contains wo consecutive selects this means that no delimiters
// If it contains two consecutive selects this means that no delimiters
// are inserted
$this->assertContains('</select><select', $markup);
}

public function testCanRenderTextDelimiters()
{
$element = new DateTimeSelect('foo');
$element->setShouldCreateEmptyOption(true);
$element->setShouldRenderDelimiters(true);
$element->setShouldShowSeconds(true);
$markup = $this->helper->__invoke($element, \IntlDateFormatter::LONG, \IntlDateFormatter::LONG, 'pt_BR');

// pattern === "d 'de' MMMM 'de' y HH'h'mm'min'ss's'"
$this->assertStringMatchesFormat('%a de %a de %a %ah%amin%as', $markup);
}

public function testInvokeProxiesToRender()
{
$element = new DateTimeSelect('foo');
Expand Down
13 changes: 12 additions & 1 deletion tests/ZendTest/Form/View/Helper/FormMonthSelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,22 @@ public function testCanDisableDelimiters()
$element->setShouldRenderDelimiters(false);
$markup = $this->helper->render($element);

// If it contains wo consecutive selects this means that no delimiters
// If it contains two consecutive selects this means that no delimiters
// are inserted
$this->assertContains('</select><select', $markup);
}

public function testCanRenderTextDelimiters()
{
$element = new MonthSelect('foo');
$element->setShouldCreateEmptyOption(true);
$element->setShouldRenderDelimiters(true);
$markup = $this->helper->__invoke($element, \IntlDateFormatter::LONG, 'pt_BR');

// pattern === "MMMM 'de' y"
$this->assertStringMatchesFormat('%a de %a', $markup);
}

public function testInvokeProxiesToRender()
{
$element = new MonthSelect('foo');
Expand Down

0 comments on commit 346b337

Please sign in to comment.