mirror of
https://github.com/friendica/friendica
synced 2026-04-19 20:37:24 +02:00
Fix "DateTimeFormat::convert: exception: Failed to parse time string"
This commit is contained in:
parent
ae84840f0d
commit
47e3ab8944
2 changed files with 24 additions and 9 deletions
|
|
@ -17,11 +17,11 @@ use Friendica\DI;
|
|||
*/
|
||||
class DateTimeFormat
|
||||
{
|
||||
const ATOM = 'Y-m-d\TH:i:s\Z';
|
||||
const MYSQL = 'Y-m-d H:i:s';
|
||||
const HTTP = 'D, d M Y H:i:s \G\M\T';
|
||||
const JSON = 'Y-m-d\TH:i:s.v\Z';
|
||||
const API = 'D M d H:i:s +0000 Y';
|
||||
public const ATOM = 'Y-m-d\TH:i:s\Z';
|
||||
public const MYSQL = 'Y-m-d H:i:s';
|
||||
public const HTTP = 'D, d M Y H:i:s \G\M\T';
|
||||
public const JSON = 'Y-m-d\TH:i:s.v\Z';
|
||||
public const API = 'D M d H:i:s +0000 Y';
|
||||
|
||||
public static $localTimezone = 'UTC';
|
||||
|
||||
|
|
@ -181,6 +181,9 @@ class DateTimeFormat
|
|||
$pregPatterns = [
|
||||
['#(\w+), (\d+ \w+ \d+) (\d+:\d+:\d+) (.+)#', '$2 $3 $4'],
|
||||
['#(\d+:\d+) (\w+), (\w+) (\d+), (\d+)#', '$1 $2 $3 $4 $5'],
|
||||
['#(GMT[+-]\d{4}) \([^)]*\)#', '$1'], // Tue Apr 07 2026 11:40:30 GMT+0530 (India Standard Time)
|
||||
['#\s+\((?:[A-Za-z]+(?: [A-Za-z]+){0,5})\)$#', ''], // Tue Apr 07 2026 11:40:30 (India Standard Time)
|
||||
['#^(\w+), ((?:1[3-9]|2\d|3[0-1]))/(0?[1-9]|1[0-2])/(\d{4}), (\d{1,2}:\d{2}(?::\d{2})?)$#', '$4-$3-$2 $5'],
|
||||
['#\[[^\]]*\]#', ''], // 2025-03-07T08:54:14.341+01:00[Europe/Berlin]
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -117,17 +117,29 @@ class DateTimeFormatTest extends MockedTestCase
|
|||
'expectedDate' => '2022-12-30T14:29:10+00:00',
|
||||
'dateString' => 'Fri Dec 30 2022 14:29:10 GMT+0000 (Coordinated Universal Time)',
|
||||
],
|
||||
'(India Standard Time)' => [
|
||||
'expectedDate' => '2026-04-07T11:40:30+05:30',
|
||||
'dateString' => 'Tue Apr 07 2026 11:40:30 GMT+0530 (India Standard Time)',
|
||||
],
|
||||
'(India Standard Time) fallback without GMT prefix' => [
|
||||
'expectedDate' => '2026-04-07T11:40:30+05:30',
|
||||
'dateString' => 'Tue Apr 07 2026 11:40:30 +0530 (India Standard Time)',
|
||||
],
|
||||
'Unambiguous day/month date string' => [
|
||||
'expectedDate' => '2026-03-19T07:26:00+00:00',
|
||||
'dateString' => 'Thu, 19/03/2026, 07:26',
|
||||
],
|
||||
'Double HTML encode' => [
|
||||
'expectedDate' => '2015-05-22T08:48:00+12:00',
|
||||
'dateString' => '2015-05-22T08:48:00+12:00'
|
||||
'dateString' => '2015-05-22T08:48:00+12:00',
|
||||
],
|
||||
'2023-04-02\T17:22:42+05:30' => [
|
||||
'expectedDate' => '2023-04-02T17:22:42+05:30',
|
||||
'dateString' => '2023-04-02\T17:22:42+05:30'
|
||||
'dateString' => '2023-04-02\T17:22:42+05:30',
|
||||
],
|
||||
'2025-03-07T08:54:14.341+01:00[Europe/Berlin]' => [
|
||||
'expectedDate' => '2025-03-07T08:54:14+01:00',
|
||||
'dateString' => '2025-03-07T08:54:14.341+01:00[Europe/Berlin]'
|
||||
'dateString' => '2025-03-07T08:54:14.341+01:00[Europe/Berlin]',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
|
@ -206,7 +218,7 @@ class DateTimeFormatTest extends MockedTestCase
|
|||
],
|
||||
'microsecond timestamp' => [
|
||||
'expected' => '2025-11-05 22:11:28',
|
||||
's' => '1762380688000'
|
||||
's' => '1762380688000',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue