fix daterange-picker for fr, hu and ar (#547)
This commit is contained in:
@@ -169,8 +169,8 @@ kimai:
|
|||||||
hu:
|
hu:
|
||||||
date_time_type: 'yyyy.MM.dd HH:mm'
|
date_time_type: 'yyyy.MM.dd HH:mm'
|
||||||
date_time_picker: 'YYYY.MM.DD HH:mm'
|
date_time_picker: 'YYYY.MM.DD HH:mm'
|
||||||
date_type: 'yyyy.MM.dd'
|
date_type: 'yyyy.MM.dd.'
|
||||||
date_picker: 'YYYY.MM.DD'
|
date_picker: 'YYYY.MM.DD.'
|
||||||
date: 'Y.m.d.'
|
date: 'Y.m.d.'
|
||||||
date_time: 'm.d. H:i'
|
date_time: 'm.d. H:i'
|
||||||
duration: '%%h:%%m h'
|
duration: '%%h:%%m h'
|
||||||
|
|||||||
@@ -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)
|
protected function formatToPattern(string $format, string $separator)
|
||||||
{
|
{
|
||||||
|
$format = preg_quote($format, '/');
|
||||||
|
|
||||||
$pattern = str_replace('d', '[0-9]{2}', $format);
|
$pattern = str_replace('d', '[0-9]{2}', $format);
|
||||||
$pattern = str_replace('m', '[0-9]{2}', $pattern);
|
$pattern = str_replace('m', '[0-9]{2}', $pattern);
|
||||||
$pattern = str_replace('Y', '[0-9]{4}', $pattern);
|
$pattern = str_replace('Y', '[0-9]{4}', $pattern);
|
||||||
@@ -105,6 +143,8 @@ class DateRangeType extends AbstractType
|
|||||||
return $range;
|
return $range;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$dates = $this->convertArabicPersian($dates);
|
||||||
|
|
||||||
if (preg_match($pattern, $dates) !== 1) {
|
if (preg_match($pattern, $dates) !== 1) {
|
||||||
throw new TransformationFailedException('Invalid date range given');
|
throw new TransformationFailedException('Invalid date range given');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user