Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix bugs for some locales! #3746

Closed
wants to merge 5 commits into from

5 participants

@iquabius

This changes fix some bugs for locales like pt_BR, es_ES and ru!
This is a continuation of the issue #3694

@bakura10

I'm not a Regex expert but at least the stripos(') === false makes sense. If there are no more errors... let's do that!

@Freeaqingme
Collaborator

@wryck7 Could you perhaps also provide a unit test? That will ensure this issue is fixed permanently.

@iquabius

@bacura10! Can you take a look at everything to make sure it is all good!

@bakura10

Looks good to me. Can be merged :).

@DASPRiD DASPRiD was assigned
@weierophinney weierophinney closed this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/3746'
Close #3746
Fixes #3694
346b337
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/3746'
Close #3746
Fixes #3694
36b0515
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/3746' into develop
Forward port #3746
6a2347f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 9, 2013
  1. @iquabius
Commits on Feb 11, 2013
  1. @iquabius

    Fix bugs for some locales!

    iquabius authored
    I had to change this too because this class overwrites the parsePattern() method.
  2. @iquabius
  3. @iquabius
  4. @iquabius
This page is out of date. Refresh to see the latest.
View
20 library/Zend/Form/View/Helper/FormDateTimeSelect.php
@@ -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;
@@ -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);
}
}
View
10 library/Zend/Form/View/Helper/FormMonthSelect.php
@@ -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);
}
}
View
13 tests/ZendTest/Form/View/Helper/FormDateSelectTest.php
@@ -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');
View
14 tests/ZendTest/Form/View/Helper/FormDateTimeSelectTest.php
@@ -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');
View
13 tests/ZendTest/Form/View/Helper/FormMonthSelectTest.php
@@ -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');
Something went wrong with that request. Please try again.