mirror of
https://github.com/friendica/friendica
synced 2024-11-10 05:02:58 +00:00
Merge pull request #11973 from MrPetovan/task/test-fixDateFormat
Add tests for DateTimeFormat::fix()
This commit is contained in:
commit
b5ad8c3e15
2 changed files with 57 additions and 2 deletions
|
@ -135,7 +135,7 @@ class DateTimeFormat
|
||||||
$s = 'now';
|
$s = 'now';
|
||||||
}
|
}
|
||||||
|
|
||||||
$s = self::fixDateFormat($s);
|
$s = self::fix($s);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Slight hackish adjustment so that 'zero' datetime actually returns what is intended
|
* Slight hackish adjustment so that 'zero' datetime actually returns what is intended
|
||||||
|
@ -178,10 +178,11 @@ class DateTimeFormat
|
||||||
/**
|
/**
|
||||||
* Fix weird date formats
|
* Fix weird date formats
|
||||||
*
|
*
|
||||||
|
* @see \Friendica\Test\src\Util\DateTimeFormatTest::dataFix() for a list of examples handled by this method.
|
||||||
* @param string $dateString
|
* @param string $dateString
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private static function fixDateFormat(string $dateString): string
|
public static function fix(string $dateString): string
|
||||||
{
|
{
|
||||||
$patterns = [
|
$patterns = [
|
||||||
['#(\w+), (\d+/\d+/\d+) - (\d+:\d+)#', '$1, $2 $3'],
|
['#(\w+), (\d+/\d+/\d+) - (\d+:\d+)#', '$1, $2 $3'],
|
||||||
|
|
|
@ -87,4 +87,58 @@ class DateTimeFormatTest extends MockedTest
|
||||||
{
|
{
|
||||||
self::assertEquals('Wed Oct 10 00:00:00 +0000 1990', DateTimeFormat::utc('1990-10-10', DateTimeFormat::API));
|
self::assertEquals('Wed Oct 10 00:00:00 +0000 1990', DateTimeFormat::utc('1990-10-10', DateTimeFormat::API));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function dataFix(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'Mo, 19 Sep 2022 14:51:00 +0200' => [
|
||||||
|
'expected' => '19 Sep 2022 14:51:00 +0200',
|
||||||
|
'dateString' => 'Mo, 19 Sep 2022 14:51:00 +0200',
|
||||||
|
],
|
||||||
|
'2020-11-21T12:00:13.745339ZZ' => [
|
||||||
|
'expected' => '2020-11-21T12:00:13.745339Z',
|
||||||
|
'dateString' => '2020-11-21T12:00:13.745339ZZ',
|
||||||
|
],
|
||||||
|
'2016-09-09T13:32:00ZZ' => [
|
||||||
|
'expected' => '2016-09-09T13:32:00Z',
|
||||||
|
'dateString' => '2016-09-09T13:32:00ZZ',
|
||||||
|
],
|
||||||
|
'2021-09-09T16:19:00ZZ' => [
|
||||||
|
'expected' => '2021-09-09T16:19:00Z',
|
||||||
|
'dateString' => '2021-09-09T16:19:00ZZ',
|
||||||
|
],
|
||||||
|
'Sun, 10/03/2021 - 12:41' => [
|
||||||
|
'expected' => 'Sun, 10/03/2021 12:41',
|
||||||
|
'dateString' => 'Sun, 10/03/2021 - 12:41',
|
||||||
|
],
|
||||||
|
'Mon, 09/12/2022 - 09:02' => [
|
||||||
|
'expected' => 'Mon, 09/12/2022 09:02',
|
||||||
|
'dateString' => 'Mon, 09/12/2022 - 09:02',
|
||||||
|
],
|
||||||
|
'4:30 PM, Sep 13, 2022' => [
|
||||||
|
'expected' => '4:30 PM Sep 13 2022',
|
||||||
|
'dateString' => '4:30 PM, Sep 13, 2022',
|
||||||
|
],
|
||||||
|
'August 27, 2022 - 21:00' => [
|
||||||
|
'expected' => 'August 27, 2022, 21:00',
|
||||||
|
'dateString' => 'August 27, 2022 - 21:00',
|
||||||
|
],
|
||||||
|
'2021-09-19T14:06:03+00:00' => [
|
||||||
|
'expected' => '2021-09-19T14:06:03+00:00',
|
||||||
|
'dateString' => '2021-09-19T14:06:03+00:00',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider dataFix
|
||||||
|
*
|
||||||
|
* @param $expected
|
||||||
|
* @param $dateString
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testFix($expected, $dateString)
|
||||||
|
{
|
||||||
|
$this->assertEquals($expected, DateTimeFormat::fix($dateString));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue