xref: /webtrees/tests/app/Date/AbstractCalendarDateTest.php (revision c642dcbb44ad1c68eb1f1abb7a08d4518323d78f)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2023 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Date;
21
22use Fisharebest\Webtrees\TestCase;
23use PHPUnit\Framework\Attributes\CoversClass;
24
25#[CoversClass(AbstractCalendarDate::class)]
26class AbstractCalendarDateTest extends TestCase
27{
28    public function testAgeDifference(): void
29    {
30        $date1 = new GregorianDate(['1900', 'FEB', '4']);
31        $date2 = new GregorianDate(['1930', 'FEB', '3']);
32        self::assertSame([29, 11, 27], $date1->ageDifference($date2));
33
34        $date1 = new GregorianDate(['1900', 'FEB', '4']);
35        $date2 = new GregorianDate(['1900', 'JUN', '3']);
36        self::assertSame([0, 3, 27], $date1->ageDifference($date2));
37
38        $date1 = new GregorianDate(['1900', 'FEB', '4']);
39        $date2 = new GregorianDate(['1900', 'JUL', '3']);
40        self::assertSame([0, 4, 27], $date1->ageDifference($date2));
41
42        $date1 = new GregorianDate(['1900', 'FEB', '4']);
43        $date2 = new GregorianDate(['1900', 'AUG', '3']);
44        self::assertSame([0, 5, 27], $date1->ageDifference($date2));
45
46        $date1 = new GregorianDate(['1900', 'FEB', '4']);
47        $date2 = new GregorianDate(['1900', 'FEB', '7']);
48        self::assertSame([0, 0, 3], $date1->ageDifference($date2));
49
50        $date1 = new GregorianDate(['1900', 'FEB', '4']);
51        $date2 = new GregorianDate(['1900', 'FEB', '4']);
52        self::assertSame([0, 0, 0], $date1->ageDifference($date2));
53
54        $date1 = new GregorianDate(['1900', 'FEB', '4']);
55        $date2 = new GregorianDate(['1900', 'FEB', '3']);
56        self::assertSame([-1, 11, 27], $date1->ageDifference($date2));
57
58        $date1 = new GregorianDate(['1930', 'FEB', '4']);
59        $date2 = new GregorianDate(['1900', 'FEB', '3']);
60        self::assertSame([-31, 11, 27], $date1->ageDifference($date2));
61    }
62
63    public function testAgeDifferenceIncomplete(): void
64    {
65        $date1 = new GregorianDate(['', 'FEB', '4']);
66        $date2 = new GregorianDate(['1900', 'FEB', '3']);
67        self::assertSame([-1, -1, -1], $date1->ageDifference($date2));
68
69        $date1 = new GregorianDate(['1900', 'FEB', '4']);
70        $date2 = new GregorianDate(['', 'FEB', '3']);
71        self::assertSame([-1, -1, -1], $date1->ageDifference($date2));
72
73        $date1 = new GregorianDate(['1900', 'FEB', '']);
74        $date2 = new GregorianDate(['1900', 'FEB', '3']);
75        self::assertSame([0, 0, 0], $date1->ageDifference($date2));
76
77        $date1 = new GregorianDate(['1900', '', '']);
78        $date2 = new GregorianDate(['1900', 'FEB', '3']);
79        self::assertSame([0, 0, 0], $date1->ageDifference($date2));
80
81        $date1 = new GregorianDate(['1900', 'FEB', '3']);
82        $date2 = new GregorianDate(['1900', 'FEB', '']);
83        self::assertSame([0, 0, 0], $date1->ageDifference($date2));
84
85        $date1 = new GregorianDate(['1900', 'FEB', '3']);
86        $date2 = new GregorianDate(['1900', '', '']);
87        self::assertSame([0, 0, 0], $date1->ageDifference($date2));
88
89        $date1 = new GregorianDate(['1900', 'JAN', '']);
90        $date2 = new GregorianDate(['1900', 'FEB', '4']);
91        self::assertSame([0, 1, 3], $date1->ageDifference($date2));
92
93        $date1 = new GregorianDate(['1900', 'JAN', '']);
94        $date2 = new GregorianDate(['1901', 'MAR', '4']);
95        self::assertSame([1, 2, 3], $date1->ageDifference($date2));
96
97        $date1 = new GregorianDate(['1900', 'JAN', '4']);
98        $date2 = new GregorianDate(['1900', 'FEB', '']);
99        self::assertSame([0, 0, 28], $date1->ageDifference($date2));
100    }
101
102    public function testAgeDifferenceOverlap(): void
103    {
104        $date1 = new GregorianDate(['1900', 'FEB', '4']);
105        $date2 = new GregorianDate(['1900', 'FEB', '']);
106        self::assertSame([0, 0, 0], $date1->ageDifference($date2));
107
108        $date1 = new GregorianDate(['1900', '', '']);
109        $date2 = new GregorianDate(['1900', 'FEB', '3']);
110        self::assertSame([0, 0, 0], $date1->ageDifference($date2));
111    }
112}
113