. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Census; use Fisharebest\Webtrees\Date; use Fisharebest\Webtrees\Individual; /** * For how many years has the individual been married. */ class CensusColumnYearsMarried extends AbstractCensusColumn implements CensusColumnInterface { /** * Generate the likely value of this census column, based on available information. * * @param Individual $individual * @param Individual $head * * @return string */ public function generate(Individual $individual, Individual $head): string { $marriage_date = null; foreach ($individual->getSpouseFamilies() as $family) { foreach ($family->facts(['MARR'], true) as $fact) { if ($fact->date()->isOK() && Date::compare($fact->date(), $this->date()) <= 0) { $marriage_date = $fact->date(); } } } if ($marriage_date === null) { return ''; } return (string) Date::getAgeYears($marriage_date, $this->date()); } }