fix daterange-picker for fr, hu and ar (#547)

This commit is contained in:
Kevin Papst
2019-02-08 20:02:23 +01:00
committed by GitHub
parent d00596d297
commit 1f99f69ecd
2 changed files with 42 additions and 2 deletions

View File

@@ -67,8 +67,46 @@ class DateRangeType extends AbstractType
});
}
/**
* A better way would be to use the Intl NumberFormatter, but if that is not available
* and the Symfony polyfill is used, this method would not work properly.
*
* @param $string
* @return string
*/
protected function convertArabicPersian($string)
{
return strtr(
$string,
[
'۰' => '0',
'۱' => '1',
'۲' => '2',
'۳' => '3',
'۴' => '4',
'۵' => '5',
'۶' => '6',
'۷' => '7',
'۸' => '8',
'۹' => '9',
'٠' => '0',
'١' => '1',
'٢' => '2',
'٣' => '3',
'٤' => '4',
'٥' => '5',
'٦' => '6',
'٧' => '7',
'٨' => '8',
'٩' => '9'
]
);
}
protected function formatToPattern(string $format, string $separator)
{
$format = preg_quote($format, '/');
$pattern = str_replace('d', '[0-9]{2}', $format);
$pattern = str_replace('m', '[0-9]{2}', $pattern);
$pattern = str_replace('Y', '[0-9]{4}', $pattern);
@@ -105,6 +143,8 @@ class DateRangeType extends AbstractType
return $range;
}
$dates = $this->convertArabicPersian($dates);
if (preg_match($pattern, $dates) !== 1) {
throw new TransformationFailedException('Invalid date range given');
}