X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=tests%2Fsrc%2FUtil%2FDateTimeFormatTest.php;h=82a294dd6e6ada4363e5c6d1eabe322674f1c505;hb=360614d2cf3aceeb763ef1281ad5236878f5d735;hp=d7bafe8b7bcef13261ea18c6395eb979f03ac9be;hpb=e56a53647bd5469551bf4f9ef2df50a5dd16b943;p=friendica.git diff --git a/tests/src/Util/DateTimeFormatTest.php b/tests/src/Util/DateTimeFormatTest.php index d7bafe8b7b..82a294dd6e 100644 --- a/tests/src/Util/DateTimeFormatTest.php +++ b/tests/src/Util/DateTimeFormatTest.php @@ -1,6 +1,6 @@ isYearMonth($input)); } + + /** + * Test the DateTimeFormat::API output. + * + * @return void + */ + public function testApiDate() + { + 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' => [ + 'expectedDate' => '2022-09-19T14:51:00+02:00', + 'dateString' => 'Mo, 19 Sep 2022 14:51:00 +0200', + ], + '2020-11-21T12:00:13.745339ZZ' => [ + 'expectedDate' => '2020-11-21T12:00:13+00:00', + 'dateString' => '2020-11-21T12:00:13.745339ZZ', + ], + '2016-09-09T13:32:00ZZ' => [ + 'expectedDate' => '2016-09-09T13:32:00+00:00', + 'dateString' => '2016-09-09T13:32:00ZZ', + ], + 'Sun, 10/03/2021 - 12:41' => [ + 'expectedDate' => '2021-10-03T12:41:00+00:00', + 'dateString' => 'Sun, 10/03/2021 - 12:41', + ], + '4:30 PM, Sep 13, 2022' => [ + 'expectedDate' => '2022-09-13T16:30:00+00:00', + 'dateString' => '4:30 PM, Sep 13, 2022', + ], + 'August 27, 2022 - 21:00' => [ + 'expectedDate' => '2022-08-27T21:00:00+00:00', + 'dateString' => 'August 27, 2022 - 21:00', + ], + '2021-09-19T14:06:03+00:00' => [ + 'expectedDate' => '2021-09-19T14:06:03+00:00', + 'dateString' => '2021-09-19T14:06:03+00:00', + ], + 'Eastern Time timezone' => [ + 'expectedDate' => '2022-09-30T00:00:00-05:00', + 'dateString' => 'September 30, 2022, 12:00 a.m. ET', + ], + 'German date time string' => [ + 'expectedDate' => '2022-10-05T16:34:00+02:00', + 'dateString' => '05 Okt 2022 16:34:00 +0200', + ], + '(Coordinated Universal Time)' => [ + 'expectedDate' => '2022-12-30T14:29:10+00:00', + 'dateString' => 'Fri Dec 30 2022 14:29:10 GMT+0000 (Coordinated Universal Time)', + ] + ]; + } + + /** + * @dataProvider dataFix + * + * @param $expectedDate + * @param $dateString + * @return void + * @throws \Exception + */ + public function testFix($expectedDate, $dateString) + { + $fixed = DateTimeFormat::fix($dateString); + + $this->assertEquals($expectedDate, (new \DateTime($fixed))->format('c')); + } + + /** + * This test is meant to ensure DateTimeFormat::fix() isn't called on relative date/time strings + * + * @return void + * @throws \Exception + */ + public function testConvertRelative() + { + $now = DateTimeFormat::utcNow('U'); + $date = DateTimeFormat::utc('now - 3 days', 'U'); + + $this->assertEquals(259200, $now - $date); + } }