From 345d307ae0334245a7e8cba85de4629cef810510 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 7 Oct 2022 17:33:52 -0400 Subject: [PATCH] Add tests for DateTimeFormat::fix() --- src/Util/DateTimeFormat.php | 1 + tests/src/Util/DateTimeFormatTest.php | 54 +++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/src/Util/DateTimeFormat.php b/src/Util/DateTimeFormat.php index 679d7fc72..862ce6e9a 100644 --- a/src/Util/DateTimeFormat.php +++ b/src/Util/DateTimeFormat.php @@ -178,6 +178,7 @@ class DateTimeFormat /** * Fix weird date formats * + * @see \Friendica\Test\src\Util\DateTimeFormatTest::dataFix() for a list of examples handled by this method. * @param string $dateString * @return string */ diff --git a/tests/src/Util/DateTimeFormatTest.php b/tests/src/Util/DateTimeFormatTest.php index db0954122..e6f43af5a 100644 --- a/tests/src/Util/DateTimeFormatTest.php +++ b/tests/src/Util/DateTimeFormatTest.php @@ -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)); } + + 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)); + } }