Exemplo n.º 1
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
     }
 }