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