Beispiel #1
0
 static function ageDifference(WT_Date $prev, WT_Date $next, $child_number = 0)
 {
     if ($prev->isOK() && $next->isOK()) {
         $days = $next->MaxJD() - $prev->MinJD();
         if ($days < 0) {
             // Show warning triangle if dates in reverse order
             $diff = '<i class="icon-warning"></i> ';
         } elseif ($child_number > 1 && $days > 1 && $days < 240) {
             // Show warning triangle if children born too close together
             $diff = '<i class="icon-warning"></i> ';
         } else {
             $diff = '';
         }
         $months = round($days * 12 / 365.25);
         // Approximate - we do not know the calendar
         if (abs($months) == 12 || abs($months) >= 24) {
             $diff .= WT_I18N::plural('%d year', '%d years', round($months / 12), round($months / 12));
         } elseif ($months != 0) {
             $diff .= WT_I18N::plural('%d month', '%d months', $months, $months);
         }
         return '<div class="elderdate age">' . $diff . '</div>';
     } else {
         return '';
     }
 }
Beispiel #2
0
 public function isDead()
 {
     global $MAX_ALIVE_AGE;
     // "1 DEAT Y" or "1 DEAT/2 DATE" or "1 DEAT/2 PLAC"
     if (preg_match('/\\n1 (?:' . WT_EVENTS_DEAT . ')(?: Y|(?:\\n[2-9].+)*\\n2 (DATE|PLAC) )/', $this->gedcom)) {
         return true;
     }
     // If any event occured more than $MAX_ALIVE_AGE years ago, then assume the individual is dead
     if (preg_match_all('/\\n2 DATE (.+)/', $this->gedcom, $date_matches)) {
         foreach ($date_matches[1] as $date_match) {
             $date = new WT_Date($date_match);
             if ($date->isOK() && $date->MaxJD() <= WT_CLIENT_JD - 365 * $MAX_ALIVE_AGE) {
                 return true;
             }
         }
         // The individual has one or more dated events.  All are less than $MAX_ALIVE_AGE years ago.
         // If one of these is a birth, the individual must be alive.
         if (preg_match('/\\n1 BIRT(?:\\n[2-9].+)*\\n2 DATE /', $this->gedcom)) {
             return false;
         }
     }
     // If we found no conclusive dates then check the dates of close relatives.
     // Check parents (birth and adopted)
     foreach ($this->getChildFamilies(WT_PRIV_HIDE) as $family) {
         foreach ($family->getSpouses(WT_PRIV_HIDE) as $parent) {
             // Assume parents are no more than 45 years older than their children
             preg_match_all('/\\n2 DATE (.+)/', $parent->gedcom, $date_matches);
             foreach ($date_matches[1] as $date_match) {
                 $date = new WT_Date($date_match);
                 if ($date->isOK() && $date->MaxJD() <= WT_CLIENT_JD - 365 * ($MAX_ALIVE_AGE + 45)) {
                     return true;
                 }
             }
         }
     }
     // Check spouses
     foreach ($this->getSpouseFamilies(WT_PRIV_HIDE) as $family) {
         preg_match_all('/\\n2 DATE (.+)/', $family->gedcom, $date_matches);
         foreach ($date_matches[1] as $date_match) {
             $date = new WT_Date($date_match);
             // Assume marriage occurs after age of 10
             if ($date->isOK() && $date->MaxJD() <= WT_CLIENT_JD - 365 * ($MAX_ALIVE_AGE - 10)) {
                 return true;
             }
         }
         // Check spouse dates
         $spouse = $family->getSpouse($this);
         if ($spouse) {
             preg_match_all('/\\n2 DATE (.+)/', $spouse->gedcom, $date_matches);
             foreach ($date_matches[1] as $date_match) {
                 $date = new WT_Date($date_match);
                 // Assume max age difference between spouses of 40 years
                 if ($date->isOK() && $date->MaxJD() <= WT_CLIENT_JD - 365 * ($MAX_ALIVE_AGE + 40)) {
                     return true;
                 }
             }
         }
         // Check child dates
         foreach ($family->getChildren(WT_PRIV_HIDE) as $child) {
             preg_match_all('/\\n2 DATE (.+)/', $child->gedcom, $date_matches);
             // Assume children born after age of 15
             foreach ($date_matches[1] as $date_match) {
                 $date = new WT_Date($date_match);
                 if ($date->isOK() && $date->MaxJD() <= WT_CLIENT_JD - 365 * ($MAX_ALIVE_AGE - 15)) {
                     return true;
                 }
             }
             // Check grandchildren
             foreach ($child->getSpouseFamilies(WT_PRIV_HIDE) as $child_family) {
                 foreach ($child_family->getChildren(WT_PRIV_HIDE) as $grandchild) {
                     preg_match_all('/\\n2 DATE (.+)/', $grandchild->gedcom, $date_matches);
                     // Assume grandchildren born after age of 30
                     foreach ($date_matches[1] as $date_match) {
                         $date = new WT_Date($date_match);
                         if ($date->isOK() && $date->MaxJD() <= WT_CLIENT_JD - 365 * ($MAX_ALIVE_AGE - 30)) {
                             return true;
                         }
                     }
                 }
             }
         }
     }
     return false;
 }
Beispiel #3
0
        for ($jd = $cal_date->minJD; $jd <= $cal_date->maxJD; ++$jd) {
            foreach (apply_filter(get_anniversary_events($jd, $events), $filterof, $filtersx) as $fact) {
                $tmp = $fact->getDate()->MinDate();
                if ($tmp->d >= 1 && $tmp->d <= $tmp->DaysInMonth()) {
                    $d = $jd - $cal_date->minJD + 1;
                } else {
                    $d = 0;
                }
                $found_facts[$d][] = $fact;
            }
        }
        break;
    case 'year':
        $cal_date->m = 0;
        $cal_date->setJdFromYmd();
        $found_facts = apply_filter(get_calendar_events($ged_date->MinJD(), $ged_date->MaxJD(), $events), $filterof, $filtersx);
        // Eliminate duplicates (e.g. BET JUL 1900 AND SEP 1900 will appear twice in 1900)
        $found_facts = array_unique($found_facts);
        break;
}
// Group the facts by family/individual
switch ($action) {
    case 'year':
    case 'today':
        $indis = array();
        $fams = array();
        foreach ($found_facts as $fact) {
            $record = $fact->getParent();
            $xref = $record->getXref();
            if ($record instanceof WT_Individual) {
                if (empty($indis[$xref])) {
Beispiel #4
0
 static function getAge(WT_Date $d1, WT_Date $d2 = null, $format)
 {
     if ($d2) {
         if ($d2->MaxJD() >= $d1->MinJD() && $d2->MinJD() <= $d1->MinJD()) {
             // Overlapping dates
             $jd = $d1->MinJD();
         } else {
             // Non-overlapping dates
             $jd = $d2->MinJD();
         }
     } else {
         // If second date not specified, use today’s date
         $jd = WT_CLIENT_JD;
     }
     switch ($format) {
         case 0:
             // Years - integer only (for statistics, rather than for display)
             if ($jd && $d1->MinJD() && $d1->MinJD() <= $jd) {
                 return $d1->MinDate()->GetAge(false, $jd, false);
             } else {
                 return -1;
             }
         case 1:
             // Days - integer only (for sorting, rather than for display)
             if ($jd && $d1->MinJD()) {
                 return $jd - $d1->MinJD();
             } else {
                 return -1;
             }
         case 2:
             // Just years, in local digits, with warning for negative/
             if ($jd && $d1->MinJD()) {
                 if ($d1->MinJD() > $jd) {
                     return '<i class="icon-warning"></i>';
                 } else {
                     return WT_I18N::number($d1->MinDate()->GetAge(false, $jd));
                 }
             } else {
                 return '&nbsp;';
             }
             // TODO: combine GetAgeGedcom() into this function
     }
 }