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