Add support for more datetime formats

- Unix Timestamp
- RFC 3339 extended + timezone name in square brackets
- Address https://github.com/friendica/friendica/issues/14647#issuecomment-2719430131
This commit is contained in:
Hypolite Petovan 2025-03-12 22:46:36 -04:00
parent 0aa350f1c8
commit 6f159e69be
2 changed files with 85 additions and 2 deletions

View file

@ -117,7 +117,7 @@ class DateTimeFormat
$tz_to = 'UTC';
}
if (($s === '') || (!is_string($s))) {
if ($s === '') {
$s = 'now';
}
@ -135,7 +135,8 @@ class DateTimeFormat
}
try {
$d = new DateTime($s, $from_obj);
$d = DateTime::createFromFormat('U', $s, $from_obj)
?: new DateTime($s, $from_obj);
} catch (Exception $e) {
try {
$d = new DateTime(self::fix($s), $from_obj);
@ -176,6 +177,7 @@ class DateTimeFormat
$pregPatterns = [
['#(\w+), (\d+ \w+ \d+) (\d+:\d+:\d+) (.+)#', '$2 $3 $4'],
['#(\d+:\d+) (\w+), (\w+) (\d+), (\d+)#', '$1 $2 $3 $4 $5'],
['#\[[^\]]*\]#', ''], // 2025-03-07T08:54:14.341+01:00[Europe/Berlin]
];
foreach ($pregPatterns as $pattern) {