diff --git a/src/View/Helper/FormDateTimeSelect.php b/src/View/Helper/FormDateTimeSelect.php index 777de2d3..74e70e87 100644 --- a/src/View/Helper/FormDateTimeSelect.php +++ b/src/View/Helper/FormDateTimeSelect.php @@ -12,6 +12,7 @@ use function array_key_exists; use function is_numeric; +use function preg_match_all; use function preg_split; use function rtrim; use function sprintf; @@ -203,7 +204,21 @@ public function getPattern(): string */ protected function parsePattern(bool $renderDelimiters = true): array { - $pattern = $this->getPattern(); + $pattern = $this->getPattern(); + + // are there any non-latin characters in the pattern? + $count = preg_match_all('/[^\p{Latin}\s\-,.:\/\\\'\[\]\(\)]+/u', $pattern, $matches); + + if ($count) { + // put single quotes around these characters + foreach ($matches[0] as $match) { + $pattern = str_replace($match, "'$match'", $pattern); + } + + // remove double quotes, if there were already quotes around them + $pattern = str_replace("''", "'", $pattern); + } + $pregResult = preg_split( "/([ \-,.:\/]*'.*?'[ \-,.:\/]*)|([ \-,.:\/]+)/", $pattern, diff --git a/test/View/Helper/FormDateTimeSelectTest.php b/test/View/Helper/FormDateTimeSelectTest.php index c10875cd..24984e29 100644 --- a/test/View/Helper/FormDateTimeSelectTest.php +++ b/test/View/Helper/FormDateTimeSelectTest.php @@ -453,4 +453,19 @@ public function testShortTimeFormatDoesNotProvideSecondPart(): void self::assertStringContainsString('', $markup); } + + public function testRendersDatesWithZhHansHKLocaleDatePattern(): void + { + $this->helper->setLocale('zh_Hans_HK'); + $this->helper->setDateType(IntlDateFormatter::LONG); + self::assertSame('y年M月d日 z ah:mm:ss', $this->helper->getPattern()); + + $element = new DateTimeSelect('foo'); + $element->setMinYear(2022); + $element->setMaxYear(2027); + + $markup = $this->helper->render($element); + + self::assertStringContainsString('