1
0
Fork 0

Add a couple of cases to DateTimeFormat::fix()

- Reworked method to perform more string replacements and fewer regular expression matches
This commit is contained in:
Hypolite Petovan 2022-10-09 09:24:06 -04:00
commit a4b0ebf160
2 changed files with 28 additions and 25 deletions

View file

@ -182,17 +182,17 @@ class DateTimeFormat
*/
public static function fix(string $dateString): string
{
$patterns = [
['#(\w+), (\d+/\d+/\d+) - (\d+:\d+)#', '$1, $2 $3'],
['#(\d+-\d+-\d+)T(\d+:\d+:\d+)ZZ#', '$1T$2Z'],
['#(\d+-\d+-\d+)T(\d+:\d+:\d+\.\d+)ZZ#', '$1T$2Z'],
$search = ['Mär', 'März', 'Mai', 'Juni', 'Juli', 'Okt', 'Dez', 'ET' , 'ZZ', ' - ', '+'];
$replace = ['Mar', 'Mar' , 'May', 'Jun' , 'Jul' , 'Oct', 'Dec', 'EST', 'Z' , ', ' , '+' ];
$dateString = str_replace($search, $replace, $dateString);
$pregPatterns = [
['#(\w+), (\d+ \w+ \d+) (\d+:\d+:\d+) (.+)#', '$2 $3 $4'],
['#(\d+:\d+) (\w+), (\w+) (\d+), (\d+)#', '$1 $2 $3 $4 $5'],
['#(\w+ \d+, \d+) - (\d+:\d+)#', '$1, $2'],
['~(\d+-\d+-\d+)T(\d+:\d+:\d+)+(\d+:\d+)~', '$1T$2+$3'],
];
foreach ($patterns as $pattern) {
foreach ($pregPatterns as $pattern) {
$dateString = preg_replace($pattern[0], $pattern[1], $dateString);
}