xref: /webtrees/tests/app/Date/AbstractCalendarDateTest.php (revision 928e8f1ab8bf8a4eae9e8ec7a464d6b65ee174d5)
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;
23
24/**
25 * Test harness for the class AbstractCalendarDate
26 */
27class AbstractCalendarDateTest extends TestCase
28{
29    /**
30     * @covers \Fisharebest\Webtrees\Date\AbstractCalendarDate::ageDifference
31     */
32    public function testAgeDifference(): void
33    {
34        $date1 = new GregorianDate(['1900', 'FEB', '4']);
35        $date2 = new GregorianDate(['1930', 'FEB', '3']);
36        self::assertSame([29, 11, 27], $date1->ageDifference($date2));
37
38        $date1 = new GregorianDate(['1900', 'FEB', '4']);
39        $date2 = new GregorianDate(['1900', 'JUN', '3']);
40        self::assertSame([0, 3, 27], $date1->ageDifference($date2));
41
42        $date1 = new GregorianDate(['1900', 'FEB', '4']);
43        $date2 = new GregorianDate(['1900', 'JUL', '3']);
44        self::assertSame([0, 4, 27], $date1->ageDifference($date2));
45
46        $date1 = new GregorianDate(['1900', 'FEB', '4']);
47        $date2 = new GregorianDate(['1900', 'AUG', '3']);
48        self::assertSame([0, 5, 27], $date1->ageDifference($date2));
49
50        $date1 = new GregorianDate(['1900', 'FEB', '4']);
51        $date2 = new GregorianDate(['1900', 'FEB', '7']);
52        self::assertSame([0, 0, 3], $date1->ageDifference($date2));
53
54        $date1 = new GregorianDate(['1900', 'FEB', '4']);
55        $date2 = new GregorianDate(['1900', 'FEB', '4']);
56        self::assertSame([0, 0, 0], $date1->ageDifference($date2));
57
58        $date1 = new GregorianDate(['1900', 'FEB', '4']);
59        $date2 = new GregorianDate(['1900', 'FEB', '3']);
60        self::assertSame([-1, 11, 27], $date1->ageDifference($date2));
61
62        $date1 = new GregorianDate(['1930', 'FEB', '4']);
63        $date2 = new GregorianDate(['1900', 'FEB', '3']);
64        self::assertSame([-31, 11, 27], $date1->ageDifference($date2));
65    }
66
67    /**
68     * @covers \Fisharebest\Webtrees\Date\AbstractCalendarDate::ageDifference
69     */
70    public function testAgeDifferenceIncomplete(): void
71    {
72        $date1 = new GregorianDate(['', 'FEB', '4']);
73        $date2 = new GregorianDate(['1900', 'FEB', '3']);
74        self::assertSame([-1, -1, -1], $date1->ageDifference($date2));
75
76        $date1 = new GregorianDate(['1900', 'FEB', '4']);
77        $date2 = new GregorianDate(['', 'FEB', '3']);
78        self::assertSame([-1, -1, -1], $date1->ageDifference($date2));
79
80        $date1 = new GregorianDate(['1900', 'FEB', '']);
81        $date2 = new GregorianDate(['1900', 'FEB', '3']);
82        self::assertSame([0, 0, 0], $date1->ageDifference($date2));
83
84        $date1 = new GregorianDate(['1900', '', '']);
85        $date2 = new GregorianDate(['1900', 'FEB', '3']);
86        self::assertSame([0, 0, 0], $date1->ageDifference($date2));
87
88        $date1 = new GregorianDate(['1900', 'FEB', '3']);
89        $date2 = new GregorianDate(['1900', 'FEB', '']);
90        self::assertSame([0, 0, 0], $date1->ageDifference($date2));
91
92        $date1 = new GregorianDate(['1900', 'FEB', '3']);
93        $date2 = new GregorianDate(['1900', '', '']);
94        self::assertSame([0, 0, 0], $date1->ageDifference($date2));
95
96        $date1 = new GregorianDate(['1900', 'JAN', '']);
97        $date2 = new GregorianDate(['1900', 'FEB', '4']);
98        self::assertSame([0, 1, 3], $date1->ageDifference($date2));
99
100        $date1 = new GregorianDate(['1900', 'JAN', '']);
101        $date2 = new GregorianDate(['1901', 'MAR', '4']);
102        self::assertSame([1, 2, 3], $date1->ageDifference($date2));
103
104        $date1 = new GregorianDate(['1900', 'JAN', '4']);
105        $date2 = new GregorianDate(['1900', 'FEB', '']);
106        self::assertSame([0, 0, 28], $date1->ageDifference($date2));
107    }
108
109    /**
110     * @covers \Fisharebest\Webtrees\Date\AbstractCalendarDate::ageDifference
111     */
112    public function testAgeDifferenceOverlap(): void
113    {
114        $date1 = new GregorianDate(['1900', 'FEB', '4']);
115        $date2 = new GregorianDate(['1900', 'FEB', '']);
116        self::assertSame([0, 0, 0], $date1->ageDifference($date2));
117
118        $date1 = new GregorianDate(['1900', '', '']);
119        $date2 = new GregorianDate(['1900', 'FEB', '3']);
120        self::assertSame([0, 0, 0], $date1->ageDifference($date2));
121    }
122}
123