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