]> git.mxchange.org Git - friendica.git/commitdiff
Issue 11938: Fix weird date formats
authorMichael <heluecht@pirati.ca>
Mon, 3 Oct 2022 16:12:22 +0000 (16:12 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 3 Oct 2022 16:12:22 +0000 (16:12 +0000)
src/Util/DateTimeFormat.php

index 872b95228fab63a849e527b9b5dc0ad58f46f670..96cddfeec928e19165677fba30f984b83e5f44a0 100644 (file)
@@ -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
         *