From 045238070b57bd20ddcb17163afc5b404deba3e6 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 3 Oct 2022 16:12:22 +0000 Subject: [PATCH 1/2] Issue 11938: Fix weird date formats --- src/Util/DateTimeFormat.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Util/DateTimeFormat.php b/src/Util/DateTimeFormat.php index 872b95228f..96cddfeec9 100644 --- a/src/Util/DateTimeFormat.php +++ b/src/Util/DateTimeFormat.php @@ -135,6 +135,8 @@ class DateTimeFormat $s = 'now'; } + $s = self::fixDateFormat($s); + /* * Slight hackish adjustment so that 'zero' datetime actually returns what is intended * otherwise we end up with -0001-11-30 ... @@ -173,6 +175,29 @@ class DateTimeFormat return $d->format($format); } + /** + * Fix weird date formats + * + * @param string $dateString + * @return string + */ + private static function fixDateFormat(string $dateString): string + { + $pattern = + [ + ['#(\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'], + ['#(\w+), (\d+ \w+ \d+) (\d+:\d+:\d+) (.+)#', '$2 $3 $4'], + ['#(\d+:\d+) (\w+), (\w+) (\d+), (\d+)#', '$1 $2 $3 $4 $5'], + ]; + + foreach ($pattern as $search_replace) { + $dateString = preg_replace($search_replace[0], $search_replace[1], $dateString); + } + return $dateString; + } + /** * Checks, if the given string is a date with the pattern YYYY-MM * From 0a7c9c66b534bf377189a5c1d1eadd0e20bf196a Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 3 Oct 2022 19:04:49 +0200 Subject: [PATCH 2/2] Update src/Util/DateTimeFormat.php Co-authored-by: Hypolite Petovan --- src/Util/DateTimeFormat.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Util/DateTimeFormat.php b/src/Util/DateTimeFormat.php index 96cddfeec9..b790e1f641 100644 --- a/src/Util/DateTimeFormat.php +++ b/src/Util/DateTimeFormat.php @@ -183,18 +183,18 @@ class DateTimeFormat */ private static function fixDateFormat(string $dateString): string { - $pattern = - [ - ['#(\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'], - ['#(\w+), (\d+ \w+ \d+) (\d+:\d+:\d+) (.+)#', '$2 $3 $4'], - ['#(\d+:\d+) (\w+), (\w+) (\d+), (\d+)#', '$1 $2 $3 $4 $5'], - ]; + $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'], + ['#(\w+), (\d+ \w+ \d+) (\d+:\d+:\d+) (.+)#', '$2 $3 $4'], + ['#(\d+:\d+) (\w+), (\w+) (\d+), (\d+)#', '$1 $2 $3 $4 $5'], + ]; - foreach ($pattern as $search_replace) { - $dateString = preg_replace($search_replace[0], $search_replace[1], $dateString); + foreach ($patterns as $pattern) { + $dateString = preg_replace($pattern[0], $pattern[1], $dateString); } + return $dateString; }