1a25f0a04SGreg Roach<?php 23976b470SGreg Roach 3a25f0a04SGreg Roach/** 4a25f0a04SGreg Roach * webtrees: online genealogy 5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 6a25f0a04SGreg Roach * This program is free software: you can redistribute it and/or modify 7a25f0a04SGreg Roach * it under the terms of the GNU General Public License as published by 8a25f0a04SGreg Roach * the Free Software Foundation, either version 3 of the License, or 9a25f0a04SGreg Roach * (at your option) any later version. 10a25f0a04SGreg Roach * This program is distributed in the hope that it will be useful, 11a25f0a04SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12a25f0a04SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13a25f0a04SGreg Roach * GNU General Public License for more details. 14a25f0a04SGreg 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/>. 16a25f0a04SGreg Roach */ 17fcfa147eSGreg Roach 18e7f56f2aSGreg Roachdeclare(strict_types=1); 19e7f56f2aSGreg Roach 2076692c8bSGreg Roachnamespace Fisharebest\Webtrees; 21a25f0a04SGreg Roach 22a25f0a04SGreg Roachuse Fisharebest\ExtCalendar\GregorianCalendar; 234a83f5d7SGreg Roachuse Fisharebest\Webtrees\Date\AbstractCalendarDate; 24a25f0a04SGreg Roach 25a25f0a04SGreg Roach/** 2676692c8bSGreg Roach * A representation of GEDCOM dates and date ranges. 2776692c8bSGreg Roach * 2876692c8bSGreg Roach * Since different calendars start their days at different times, (civil 29a25f0a04SGreg Roach * midnight, solar midnight, sunset, sunrise, etc.), we convert on the basis of 30a25f0a04SGreg Roach * midday. 31a25f0a04SGreg Roach * 3276692c8bSGreg Roach * We assume that years start on the first day of the first month. Where 33a25f0a04SGreg Roach * this is not the case (e.g. England prior to 1752), we need to use modified 34a25f0a04SGreg Roach * years or the OS/NS notation "4 FEB 1750/51". 35a25f0a04SGreg Roach */ 36c1010edaSGreg Roachclass Date 37c1010edaSGreg Roach{ 3833c746f1SGreg Roach // Optional qualifier, such as BEF, FROM, ABT 3933c746f1SGreg Roach public string $qual1 = ''; 40a25f0a04SGreg Roach 4133c746f1SGreg Roach // The first (or only) date 4233c746f1SGreg Roach private AbstractCalendarDate $date1; 43a25f0a04SGreg Roach 4433c746f1SGreg Roach // Optional qualifier, such as TO, AND 4533c746f1SGreg Roach public string $qual2 = ''; 46a25f0a04SGreg Roach 4733c746f1SGreg Roach // Optional second date 481ff45046SGreg Roach private AbstractCalendarDate|null $date2 = null; 49a25f0a04SGreg Roach 5033c746f1SGreg Roach // Optional text, as included with an INTerpreted date 5133c746f1SGreg Roach private string $text = ''; 52a25f0a04SGreg Roach 53a25f0a04SGreg Roach /** 54a25f0a04SGreg Roach * Create a date, from GEDCOM data. 55a25f0a04SGreg Roach * 56a25f0a04SGreg Roach * @param string $date A date in GEDCOM format 57a25f0a04SGreg Roach */ 58cfe766afSGreg Roach public function __construct(string $date) 59c1010edaSGreg Roach { 60f882f05dSGreg Roach $calendar_date_factory = Registry::calendarDateFactory(); 61f882f05dSGreg Roach 62a25f0a04SGreg Roach // Extract any explanatory text 63a25f0a04SGreg Roach if (preg_match('/^(.*) ?[(](.*)[)]/', $date, $match)) { 64a25f0a04SGreg Roach $date = $match[1]; 65a25f0a04SGreg Roach $this->text = $match[2]; 66a25f0a04SGreg Roach } 67a25f0a04SGreg Roach if (preg_match('/^(FROM|BET) (.+) (AND|TO) (.+)/', $date, $match)) { 68a25f0a04SGreg Roach $this->qual1 = $match[1]; 69f882f05dSGreg Roach $this->date1 = $calendar_date_factory->make($match[2]); 70a25f0a04SGreg Roach $this->qual2 = $match[3]; 71f882f05dSGreg Roach $this->date2 = $calendar_date_factory->make($match[4]); 723506b2e5SGreg Roach } elseif (preg_match('/^(TO|FROM|BEF|AFT|CAL|EST|INT|ABT) (.+)/', $date, $match)) { 73a25f0a04SGreg Roach $this->qual1 = $match[1]; 74f882f05dSGreg Roach $this->date1 = $calendar_date_factory->make($match[2]); 75a25f0a04SGreg Roach } else { 76f882f05dSGreg Roach $this->date1 = $calendar_date_factory->make($date); 77a25f0a04SGreg Roach } 78a25f0a04SGreg Roach } 79a25f0a04SGreg Roach 80a25f0a04SGreg Roach /** 81a25f0a04SGreg Roach * When we copy a date object, we need to create copies of 82a25f0a04SGreg Roach * its child objects. 83a25f0a04SGreg Roach */ 84c1010edaSGreg Roach public function __clone() 85c1010edaSGreg Roach { 86a25f0a04SGreg Roach $this->date1 = clone $this->date1; 877e96c925SGreg Roach if ($this->date2 !== null) { 88a25f0a04SGreg Roach $this->date2 = clone $this->date2; 89a25f0a04SGreg Roach } 90a25f0a04SGreg Roach } 91a25f0a04SGreg Roach 92a25f0a04SGreg Roach /** 93a25f0a04SGreg Roach * Convert a date to the preferred format and calendar(s) display. 94a25f0a04SGreg Roach * 9566ecd017SGreg Roach * @param Tree|null $tree Wrap the date in a link to the calendar page for the tree 96a25f0a04SGreg Roach * @param string|null $date_format Override the default date format 9766ecd017SGreg Roach * @param bool $convert_calendars Convert the date into other calendars (requires a tree) 98a25f0a04SGreg Roach * 99a25f0a04SGreg Roach * @return string 100a25f0a04SGreg Roach */ 1012c6f1bd5SGreg Roach public function display(Tree|null $tree = null, string|null $date_format = null, bool $convert_calendars = false): string 102c1010edaSGreg Roach { 10366ecd017SGreg Roach if ($tree instanceof Tree) { 10412dcbc32SGreg Roach $CALENDAR_FORMAT = $tree->getPreference('CALENDAR_FORMAT'); 1053cccdb42SGreg Roach } else { 10666ecd017SGreg Roach $CALENDAR_FORMAT = 'none'; 1073cccdb42SGreg Roach } 108a25f0a04SGreg Roach 1093529c469SGreg Roach $date_format ??= I18N::dateFormat(); 110a25f0a04SGreg Roach 111a25f0a04SGreg Roach if ($convert_calendars) { 112a25f0a04SGreg Roach $calendar_format = explode('_and_', $CALENDAR_FORMAT); 113a25f0a04SGreg Roach } else { 11413abd6f3SGreg Roach $calendar_format = []; 115a25f0a04SGreg Roach } 116a25f0a04SGreg Roach 117a25f0a04SGreg Roach // Two dates with text before, between and after 118a25f0a04SGreg Roach $q1 = $this->qual1; 119a25f0a04SGreg Roach $d1 = $this->date1->format($date_format, $this->qual1); 120a25f0a04SGreg Roach $q2 = $this->qual2; 1218f038c36SRico Sonntag if ($this->date2 === null) { 122a25f0a04SGreg Roach $d2 = ''; 123a25f0a04SGreg Roach } else { 124a25f0a04SGreg Roach $d2 = $this->date2->format($date_format, $this->qual2); 125a25f0a04SGreg Roach } 126a25f0a04SGreg Roach // Con vert to other calendars, if requested 127a25f0a04SGreg Roach $conv1 = ''; 128a25f0a04SGreg Roach $conv2 = ''; 129a25f0a04SGreg Roach foreach ($calendar_format as $cal_fmt) { 130e364afe4SGreg Roach if ($cal_fmt !== 'none') { 131a25f0a04SGreg Roach $d1conv = $this->date1->convertToCalendar($cal_fmt); 132a25f0a04SGreg Roach if ($d1conv->inValidRange()) { 133a25f0a04SGreg Roach $d1tmp = $d1conv->format($date_format, $this->qual1); 134a25f0a04SGreg Roach } else { 135a25f0a04SGreg Roach $d1tmp = ''; 136a25f0a04SGreg Roach } 1378f038c36SRico Sonntag if ($this->date2 === null) { 138a25f0a04SGreg Roach $d2conv = null; 139a25f0a04SGreg Roach $d2tmp = ''; 140a25f0a04SGreg Roach } else { 141a25f0a04SGreg Roach $d2conv = $this->date2->convertToCalendar($cal_fmt); 142a25f0a04SGreg Roach if ($d2conv->inValidRange()) { 143a25f0a04SGreg Roach $d2tmp = $d2conv->format($date_format, $this->qual2); 144a25f0a04SGreg Roach } else { 145a25f0a04SGreg Roach $d2tmp = ''; 146a25f0a04SGreg Roach } 147a25f0a04SGreg Roach } 148d4f10423SGreg Roach // If the date is different from the unconverted date, add it to the date string. 1497fa97a69SGreg Roach if ($d1 !== $d1tmp && $d1tmp !== '') { 15066ecd017SGreg Roach if ($tree instanceof Tree) { 1513cfaf201SGreg Roach if ($CALENDAR_FORMAT !== 'none') { 1527560a51fSGreg Roach $conv1 .= ' <span dir="' . I18N::direction() . '">(<a href="' . e($d1conv->calendarUrl($date_format, $tree)) . '" rel="nofollow">' . $d1tmp . '</a>)</span>'; 153a25f0a04SGreg Roach } else { 1547560a51fSGreg Roach $conv1 .= ' <span dir="' . I18N::direction() . '"><br><a href="' . e($d1conv->calendarUrl($date_format, $tree)) . '" rel="nofollow">' . $d1tmp . '</a></span>'; 155a25f0a04SGreg Roach } 156a25f0a04SGreg Roach } else { 157c0af647eSGreg Roach $conv1 .= ' <span dir="' . I18N::direction() . '">(' . $d1tmp . ')</span>'; 158a25f0a04SGreg Roach } 159a25f0a04SGreg Roach } 1607fa97a69SGreg Roach if ($this->date2 !== null && $d2 !== $d2tmp && $d1tmp !== '') { 16166ecd017SGreg Roach if ($tree instanceof Tree) { 1627560a51fSGreg Roach $conv2 .= ' <span dir="' . I18N::direction() . '">(<a href="' . e($d2conv->calendarUrl($date_format, $tree)) . '" rel="nofollow">' . $d2tmp . '</a>)</span>'; 163a25f0a04SGreg Roach } else { 164c0af647eSGreg Roach $conv2 .= ' <span dir="' . I18N::direction() . '">(' . $d2tmp . ')</span>'; 165a25f0a04SGreg Roach } 166a25f0a04SGreg Roach } 167a25f0a04SGreg Roach } 168a25f0a04SGreg Roach } 169a25f0a04SGreg Roach 170a25f0a04SGreg Roach // Add URLs, if requested 17166ecd017SGreg Roach if ($tree instanceof Tree) { 1727560a51fSGreg Roach $d1 = '<a href="' . e($this->date1->calendarUrl($date_format, $tree)) . '" rel="nofollow">' . $d1 . '</a>'; 1734a83f5d7SGreg Roach if ($this->date2 instanceof AbstractCalendarDate) { 1747560a51fSGreg Roach $d2 = '<a href="' . e($this->date2->calendarUrl($date_format, $tree)) . '" rel="nofollow">' . $d2 . '</a>'; 175a25f0a04SGreg Roach } 176a25f0a04SGreg Roach } 177a25f0a04SGreg Roach 178a25f0a04SGreg Roach // Localise the date 179a25f0a04SGreg Roach switch ($q1 . $q2) { 180a25f0a04SGreg Roach case '': 181a25f0a04SGreg Roach $tmp = $d1 . $conv1; 182*61b7f600SFranz Frese if ($this->text !== '') { 183*61b7f600SFranz Frese $tmp .= '(' . e($this->text) . ')'; 184*61b7f600SFranz Frese } 185a25f0a04SGreg Roach break; 186a25f0a04SGreg Roach case 'ABT': 187bbb76c12SGreg Roach /* I18N: Gedcom ABT dates */ 188bbb76c12SGreg Roach $tmp = I18N::translate('about %s', $d1 . $conv1); 189a25f0a04SGreg Roach break; 190a25f0a04SGreg Roach case 'CAL': 191bbb76c12SGreg Roach /* I18N: Gedcom CAL dates */ 192bbb76c12SGreg Roach $tmp = I18N::translate('calculated %s', $d1 . $conv1); 193a25f0a04SGreg Roach break; 194a25f0a04SGreg Roach case 'EST': 195bbb76c12SGreg Roach /* I18N: Gedcom EST dates */ 196bbb76c12SGreg Roach $tmp = I18N::translate('estimated %s', $d1 . $conv1); 197a25f0a04SGreg Roach break; 198a25f0a04SGreg Roach case 'INT': 199bbb76c12SGreg Roach /* I18N: Gedcom INT dates */ 200bbb76c12SGreg Roach $tmp = I18N::translate('interpreted %s (%s)', $d1 . $conv1, e($this->text)); 201a25f0a04SGreg Roach break; 202a25f0a04SGreg Roach case 'BEF': 203bbb76c12SGreg Roach /* I18N: Gedcom BEF dates */ 204bbb76c12SGreg Roach $tmp = I18N::translate('before %s', $d1 . $conv1); 205a25f0a04SGreg Roach break; 206a25f0a04SGreg Roach case 'AFT': 207bbb76c12SGreg Roach /* I18N: Gedcom AFT dates */ 208bbb76c12SGreg Roach $tmp = I18N::translate('after %s', $d1 . $conv1); 209a25f0a04SGreg Roach break; 210a25f0a04SGreg Roach case 'FROM': 211bbb76c12SGreg Roach /* I18N: Gedcom FROM dates */ 212bbb76c12SGreg Roach $tmp = I18N::translate('from %s', $d1 . $conv1); 213a25f0a04SGreg Roach break; 214a25f0a04SGreg Roach case 'TO': 215bbb76c12SGreg Roach /* I18N: Gedcom TO dates */ 216bbb76c12SGreg Roach $tmp = I18N::translate('to %s', $d1 . $conv1); 217a25f0a04SGreg Roach break; 218a25f0a04SGreg Roach case 'BETAND': 219bbb76c12SGreg Roach /* I18N: Gedcom BET-AND dates */ 220bbb76c12SGreg Roach $tmp = I18N::translate('between %s and %s', $d1 . $conv1, $d2 . $conv2); 221a25f0a04SGreg Roach break; 222a25f0a04SGreg Roach case 'FROMTO': 223bbb76c12SGreg Roach /* I18N: Gedcom FROM-TO dates */ 224bbb76c12SGreg Roach $tmp = I18N::translate('from %s to %s', $d1 . $conv1, $d2 . $conv2); 225a25f0a04SGreg Roach break; 226a25f0a04SGreg Roach default: 227a25f0a04SGreg Roach $tmp = I18N::translate('Invalid date'); 228bbb76c12SGreg Roach break; 229a25f0a04SGreg Roach } 230a25f0a04SGreg Roach 2315fec6c0aSGreg Roach if (strip_tags($tmp) === '') { 2325fec6c0aSGreg Roach return ''; 233a25f0a04SGreg Roach } 234b2ce94c6SRico Sonntag 235b2ce94c6SRico Sonntag return '<span class="date">' . $tmp . '</span>'; 236a25f0a04SGreg Roach } 237a25f0a04SGreg Roach 238a25f0a04SGreg Roach /** 239a25f0a04SGreg Roach * Get the earliest calendar date from this GEDCOM date. 240a25f0a04SGreg Roach * 241a25f0a04SGreg Roach * In the date “FROM 1900 TO 1910”, this would be 1900. 242a25f0a04SGreg Roach * 2434a83f5d7SGreg Roach * @return AbstractCalendarDate 244a25f0a04SGreg Roach */ 2454a83f5d7SGreg Roach public function minimumDate(): AbstractCalendarDate 246c1010edaSGreg Roach { 247a25f0a04SGreg Roach return $this->date1; 248a25f0a04SGreg Roach } 249a25f0a04SGreg Roach 250a25f0a04SGreg Roach /** 251a25f0a04SGreg Roach * Get the latest calendar date from this GEDCOM date. 252a25f0a04SGreg Roach * 253a25f0a04SGreg Roach * In the date “FROM 1900 TO 1910”, this would be 1910. 254a25f0a04SGreg Roach * 2554a83f5d7SGreg Roach * @return AbstractCalendarDate 256a25f0a04SGreg Roach */ 257e364afe4SGreg Roach public function maximumDate(): AbstractCalendarDate 258c1010edaSGreg Roach { 259af2489e5SGreg Roach return $this->date2 ?? $this->date1; 260a25f0a04SGreg Roach } 261a25f0a04SGreg Roach 262a25f0a04SGreg Roach /** 263a25f0a04SGreg Roach * Get the earliest Julian day number from this GEDCOM date. 264a25f0a04SGreg Roach * 265cbc1590aSGreg Roach * @return int 266a25f0a04SGreg Roach */ 2678f53f488SRico Sonntag public function minimumJulianDay(): int 268c1010edaSGreg Roach { 269af2489e5SGreg Roach return $this->minimumDate()->minimumJulianDay(); 270a25f0a04SGreg Roach } 271a25f0a04SGreg Roach 272a25f0a04SGreg Roach /** 273a25f0a04SGreg Roach * Get the latest Julian day number from this GEDCOM date. 274a25f0a04SGreg Roach * 275cbc1590aSGreg Roach * @return int 276a25f0a04SGreg Roach */ 2778f53f488SRico Sonntag public function maximumJulianDay(): int 278c1010edaSGreg Roach { 279af2489e5SGreg Roach return $this->maximumDate()->maximumJulianDay(); 280a25f0a04SGreg Roach } 281a25f0a04SGreg Roach 282a25f0a04SGreg Roach /** 283a25f0a04SGreg Roach * Get the middle Julian day number from the GEDCOM date. 284a25f0a04SGreg Roach * 285f5b60decSGreg Roach * For a month-only date, this would be somewhere around the 16th day. 286a25f0a04SGreg Roach * For a year-only date, this would be somewhere around 1st July. 287a25f0a04SGreg Roach * 288cbc1590aSGreg Roach * @return int 289a25f0a04SGreg Roach */ 2908f53f488SRico Sonntag public function julianDay(): int 291c1010edaSGreg Roach { 292cdaafeeeSGreg Roach return intdiv($this->minimumJulianDay() + $this->maximumJulianDay(), 2); 293a25f0a04SGreg Roach } 294a25f0a04SGreg Roach 295a25f0a04SGreg Roach /** 296a25f0a04SGreg Roach * Offset this date by N years, and round to the whole year. 297a25f0a04SGreg Roach * 298a25f0a04SGreg Roach * This is typically used to create an estimated death date, 299a25f0a04SGreg Roach * which is before a certain number of years after the birth date. 300a25f0a04SGreg Roach * 301cbc1590aSGreg Roach * @param int $years a number of years, positive or negative 302cbc1590aSGreg Roach * @param string $qualifier typically “BEF” or “AFT” 303a25f0a04SGreg Roach * 304a25f0a04SGreg Roach * @return Date 305a25f0a04SGreg Roach */ 3068f53f488SRico Sonntag public function addYears(int $years, string $qualifier = ''): Date 307c1010edaSGreg Roach { 308a25f0a04SGreg Roach $tmp = clone $this; 3094a83f5d7SGreg Roach $tmp->date1->year += $years; 3104a83f5d7SGreg Roach $tmp->date1->month = 0; 3114a83f5d7SGreg Roach $tmp->date1->day = 0; 312a25f0a04SGreg Roach $tmp->date1->setJdFromYmd(); 313a25f0a04SGreg Roach $tmp->qual1 = $qualifier; 314a25f0a04SGreg Roach $tmp->qual2 = ''; 315a25f0a04SGreg Roach $tmp->date2 = null; 316a25f0a04SGreg Roach 317a25f0a04SGreg Roach return $tmp; 318a25f0a04SGreg Roach } 319a25f0a04SGreg Roach 320a25f0a04SGreg Roach /** 321a25f0a04SGreg Roach * Compare two dates, so they can be sorted. 322a25f0a04SGreg Roach * 323054771e9SGreg Roach * return -1 if $a<$b 324054771e9SGreg Roach * return +1 if $b>$a 325a25f0a04SGreg Roach * return 0 if dates same/overlap 326a25f0a04SGreg Roach * BEF/AFT sort as the day before/after 327a25f0a04SGreg Roach * 328a25f0a04SGreg Roach * @param Date $a 329a25f0a04SGreg Roach * @param Date $b 330a25f0a04SGreg Roach * 331cbc1590aSGreg Roach * @return int 332a25f0a04SGreg Roach */ 333e364afe4SGreg Roach public static function compare(Date $a, Date $b): int 334c1010edaSGreg Roach { 335a25f0a04SGreg Roach // Get min/max JD for each date. 336a25f0a04SGreg Roach switch ($a->qual1) { 337a25f0a04SGreg Roach case 'BEF': 338f5b60decSGreg Roach $amin = $a->minimumJulianDay() - 1; 339a25f0a04SGreg Roach $amax = $amin; 340a25f0a04SGreg Roach break; 341a25f0a04SGreg Roach case 'AFT': 342f5b60decSGreg Roach $amax = $a->maximumJulianDay() + 1; 343a25f0a04SGreg Roach $amin = $amax; 344a25f0a04SGreg Roach break; 345a25f0a04SGreg Roach default: 346f5b60decSGreg Roach $amin = $a->minimumJulianDay(); 347f5b60decSGreg Roach $amax = $a->maximumJulianDay(); 348a25f0a04SGreg Roach break; 349a25f0a04SGreg Roach } 350a25f0a04SGreg Roach switch ($b->qual1) { 351a25f0a04SGreg Roach case 'BEF': 352f5b60decSGreg Roach $bmin = $b->minimumJulianDay() - 1; 353a25f0a04SGreg Roach $bmax = $bmin; 354a25f0a04SGreg Roach break; 355a25f0a04SGreg Roach case 'AFT': 356f5b60decSGreg Roach $bmax = $b->maximumJulianDay() + 1; 357a25f0a04SGreg Roach $bmin = $bmax; 358a25f0a04SGreg Roach break; 359a25f0a04SGreg Roach default: 360f5b60decSGreg Roach $bmin = $b->minimumJulianDay(); 361f5b60decSGreg Roach $bmax = $b->maximumJulianDay(); 362a25f0a04SGreg Roach break; 363a25f0a04SGreg Roach } 364a25f0a04SGreg Roach if ($amax < $bmin) { 365a25f0a04SGreg Roach return -1; 366a25f0a04SGreg Roach } 367b2ce94c6SRico Sonntag 368b2ce94c6SRico Sonntag if ($amin > $bmax && $bmax > 0) { 369b2ce94c6SRico Sonntag return 1; 370b2ce94c6SRico Sonntag } 371b2ce94c6SRico Sonntag 372b2ce94c6SRico Sonntag if ($amin < $bmin && $amax <= $bmax) { 373b2ce94c6SRico Sonntag return -1; 374b2ce94c6SRico Sonntag } 375b2ce94c6SRico Sonntag 376b2ce94c6SRico Sonntag if ($amin > $bmin && $amax >= $bmax && $bmax > 0) { 377b2ce94c6SRico Sonntag return 1; 378b2ce94c6SRico Sonntag } 379b2ce94c6SRico Sonntag 380b2ce94c6SRico Sonntag return 0; 381a25f0a04SGreg Roach } 382a25f0a04SGreg Roach 383a25f0a04SGreg Roach /** 384a25f0a04SGreg Roach * Check whether a gedcom date contains usable calendar date(s). 385a25f0a04SGreg Roach * 386a25f0a04SGreg Roach * An incomplete date such as "12 AUG" would be invalid, as 387a25f0a04SGreg Roach * we cannot sort it. 388a25f0a04SGreg Roach * 389cbc1590aSGreg Roach * @return bool 390a25f0a04SGreg Roach */ 3918f53f488SRico Sonntag public function isOK(): bool 392c1010edaSGreg Roach { 393f5b60decSGreg Roach return $this->minimumJulianDay() && $this->maximumJulianDay(); 394a25f0a04SGreg Roach } 395a25f0a04SGreg Roach 396a25f0a04SGreg Roach /** 397a25f0a04SGreg Roach * Calculate the gregorian year for a date. This should NOT be used internally 398a25f0a04SGreg Roach * within WT - we should keep the code "calendar neutral" to allow support for 399a25f0a04SGreg Roach * jewish/arabic users. This is only for interfacing with external entities, 400a25f0a04SGreg Roach * such as the ancestry.com search interface or the dated fact icons. 401a25f0a04SGreg Roach * 402cbc1590aSGreg Roach * @return int 403a25f0a04SGreg Roach */ 404e364afe4SGreg Roach public function gregorianYear(): int 405c1010edaSGreg Roach { 406a25f0a04SGreg Roach if ($this->isOK()) { 40759f2f229SGreg Roach $gregorian_calendar = new GregorianCalendar(); 40865e02381SGreg Roach [$year] = $gregorian_calendar->jdToYmd($this->julianDay()); 409a25f0a04SGreg Roach 410a25f0a04SGreg Roach return $year; 411a25f0a04SGreg Roach } 412b2ce94c6SRico Sonntag 413b2ce94c6SRico Sonntag return 0; 414a25f0a04SGreg Roach } 415a25f0a04SGreg Roach} 416