summaryrefslogtreecommitdiff
path: root/tests/app/Date/AbstractCalendarDateTest.php
blob: da69372d4257771cc2778626e87d8dbed098da00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php

/**
 * webtrees: online genealogy
 * Copyright (C) 2025 webtrees development team
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
 */

declare(strict_types=1);

namespace Fisharebest\Webtrees\Date;

use Fisharebest\Webtrees\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;

#[CoversClass(AbstractCalendarDate::class)]
class AbstractCalendarDateTest extends TestCase
{
    public function testAgeDifference(): void
    {
        $date1 = new GregorianDate(['1900', 'FEB', '4']);
        $date2 = new GregorianDate(['1930', 'FEB', '3']);
        self::assertSame([29, 11, 27], $date1->ageDifference($date2));

        $date1 = new GregorianDate(['1900', 'FEB', '4']);
        $date2 = new GregorianDate(['1900', 'JUN', '3']);
        self::assertSame([0, 3, 27], $date1->ageDifference($date2));

        $date1 = new GregorianDate(['1900', 'FEB', '4']);
        $date2 = new GregorianDate(['1900', 'JUL', '3']);
        self::assertSame([0, 4, 27], $date1->ageDifference($date2));

        $date1 = new GregorianDate(['1900', 'FEB', '4']);
        $date2 = new GregorianDate(['1900', 'AUG', '3']);
        self::assertSame([0, 5, 27], $date1->ageDifference($date2));

        $date1 = new GregorianDate(['1900', 'FEB', '4']);
        $date2 = new GregorianDate(['1900', 'FEB', '7']);
        self::assertSame([0, 0, 3], $date1->ageDifference($date2));

        $date1 = new GregorianDate(['1900', 'FEB', '4']);
        $date2 = new GregorianDate(['1900', 'FEB', '4']);
        self::assertSame([0, 0, 0], $date1->ageDifference($date2));

        $date1 = new GregorianDate(['1900', 'FEB', '4']);
        $date2 = new GregorianDate(['1900', 'FEB', '3']);
        self::assertSame([-1, 11, 27], $date1->ageDifference($date2));

        $date1 = new GregorianDate(['1930', 'FEB', '4']);
        $date2 = new GregorianDate(['1900', 'FEB', '3']);
        self::assertSame([-31, 11, 27], $date1->ageDifference($date2));
    }

    public function testAgeDifferenceIncomplete(): void
    {
        $date1 = new GregorianDate(['', 'FEB', '4']);
        $date2 = new GregorianDate(['1900', 'FEB', '3']);
        self::assertSame([-1, -1, -1], $date1->ageDifference($date2));

        $date1 = new GregorianDate(['1900', 'FEB', '4']);
        $date2 = new GregorianDate(['', 'FEB', '3']);
        self::assertSame([-1, -1, -1], $date1->ageDifference($date2));

        $date1 = new GregorianDate(['1900', 'FEB', '']);
        $date2 = new GregorianDate(['1900', 'FEB', '3']);
        self::assertSame([0, 0, 0], $date1->ageDifference($date2));

        $date1 = new GregorianDate(['1900', '', '']);
        $date2 = new GregorianDate(['1900', 'FEB', '3']);
        self::assertSame([0, 0, 0], $date1->ageDifference($date2));

        $date1 = new GregorianDate(['1900', 'FEB', '3']);
        $date2 = new GregorianDate(['1900', 'FEB', '']);
        self::assertSame([0, 0, 0], $date1->ageDifference($date2));

        $date1 = new GregorianDate(['1900', 'FEB', '3']);
        $date2 = new GregorianDate(['1900', '', '']);
        self::assertSame([0, 0, 0], $date1->ageDifference($date2));

        $date1 = new GregorianDate(['1900', 'JAN', '']);
        $date2 = new GregorianDate(['1900', 'FEB', '4']);
        self::assertSame([0, 1, 3], $date1->ageDifference($date2));

        $date1 = new GregorianDate(['1900', 'JAN', '']);
        $date2 = new GregorianDate(['1901', 'MAR', '4']);
        self::assertSame([1, 2, 3], $date1->ageDifference($date2));

        $date1 = new GregorianDate(['1900', 'JAN', '4']);
        $date2 = new GregorianDate(['1900', 'FEB', '']);
        self::assertSame([0, 0, 28], $date1->ageDifference($date2));
    }

    public function testAgeDifferenceOverlap(): void
    {
        $date1 = new GregorianDate(['1900', 'FEB', '4']);
        $date2 = new GregorianDate(['1900', 'FEB', '']);
        self::assertSame([0, 0, 0], $date1->ageDifference($date2));

        $date1 = new GregorianDate(['1900', '', '']);
        $date2 = new GregorianDate(['1900', 'FEB', '3']);
        self::assertSame([0, 0, 0], $date1->ageDifference($date2));
    }
}