3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Test\src\Util;
24 use Friendica\Test\MockedTest;
25 use Friendica\Util\DateTimeFormat;
27 class DateTimeFormatTest extends MockedTest
29 public function dataYearMonth()
36 'validOneCharMonth' => [
40 'validTwoCharMonth' => [
72 * @dataProvider dataYearMonth
74 public function testIsYearMonth(string $input, bool $assert)
76 $dtFormat = new DateTimeFormat();
78 self::assertEquals($assert, $dtFormat->isYearMonth($input));
82 * Test the DateTimeFormat::API output.
86 public function testApiDate()
88 self::assertEquals('Wed Oct 10 00:00:00 +0000 1990', DateTimeFormat::utc('1990-10-10', DateTimeFormat::API));
91 public function dataFix(): array
94 'Mo, 19 Sep 2022 14:51:00 +0200' => [
95 'expected' => '19 Sep 2022 14:51:00 +0200',
96 'dateString' => 'Mo, 19 Sep 2022 14:51:00 +0200',
98 '2020-11-21T12:00:13.745339ZZ' => [
99 'expected' => '2020-11-21T12:00:13.745339Z',
100 'dateString' => '2020-11-21T12:00:13.745339ZZ',
102 '2016-09-09T13:32:00ZZ' => [
103 'expected' => '2016-09-09T13:32:00Z',
104 'dateString' => '2016-09-09T13:32:00ZZ',
106 '2021-09-09T16:19:00ZZ' => [
107 'expected' => '2021-09-09T16:19:00Z',
108 'dateString' => '2021-09-09T16:19:00ZZ',
110 'Sun, 10/03/2021 - 12:41' => [
111 'expected' => 'Sun, 10/03/2021 12:41',
112 'dateString' => 'Sun, 10/03/2021 - 12:41',
114 'Mon, 09/12/2022 - 09:02' => [
115 'expected' => 'Mon, 09/12/2022 09:02',
116 'dateString' => 'Mon, 09/12/2022 - 09:02',
118 '4:30 PM, Sep 13, 2022' => [
119 'expected' => '4:30 PM Sep 13 2022',
120 'dateString' => '4:30 PM, Sep 13, 2022',
122 'August 27, 2022 - 21:00' => [
123 'expected' => 'August 27, 2022, 21:00',
124 'dateString' => 'August 27, 2022 - 21:00',
126 '2021-09-19T14:06:03+00:00' => [
127 'expected' => '2021-09-19T14:06:03+00:00',
128 'dateString' => '2021-09-19T14:06:03+00:00',
134 * @dataProvider dataFix
140 public function testFix($expected, $dateString)
142 $this->assertEquals($expected, DateTimeFormat::fix($dateString));
146 * This test is meant to ensure DateTimeFormat::fix() isn't called on relative date/time strings
151 public function testConvertRelative()
153 $now = DateTimeFormat::utcNow('U');
154 $date = DateTimeFormat::utc('now - 3 days', 'U');
156 $this->assertEquals(259200, $now - $date);