mirror of
https://github.com/friendica/friendica
synced 2024-12-23 04:00:15 +00:00
Merge pull request #11958 from annando/issue-11938
Issue 11938: Fix weird date formats
This commit is contained in:
commit
241bd47896
1 changed files with 25 additions and 0 deletions
|
@ -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
|
||||
{
|
||||
$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 ($patterns as $pattern) {
|
||||
$dateString = preg_replace($pattern[0], $pattern[1], $dateString);
|
||||
}
|
||||
|
||||
return $dateString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks, if the given string is a date with the pattern YYYY-MM
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue