=== verändert Datei library/WT/Stats.php
--- library/WT/Stats.php 2013-02-02 21:14:34 +0000
+++ library/WT/Stats.php 2013-04-08 12:09:20 +0000
@@ -1482,6 +1482,9 @@
$total=(int)$total;
$rows=self::_runSQL(
"SELECT SQL_CACHE".
+
+ ' birth.d_day, birth.d_mon, birth.d_year,' .
+
" birth.d_gid AS id,".
" MIN(birth.d_julianday1) AS age".
" FROM".
@@ -1503,14 +1506,11 @@
$top10 = array();
foreach ($rows as $row) {
$person=WT_Person::getInstance($row['id']);
- $age = (WT_CLIENT_JD-$row['age']);
- if ((int)($age/365.25)>0) {
- $age = (int)($age/365.25).'y';
- } else if ((int)($age/30.4375)>0) {
- $age = (int)($age/30.4375).'m';
- } else {
- $age = $age.'d';
- }
+
+ $age = $this->getAgeString(
+ $row['d_day'], $row['d_mon'], $row['d_year']
+ );
+
$age = get_age_at_event($age, true);
if ($type == 'list') {
$top10[]="
getHtmlUrl()."\">".$person->getFullName()." (".$age.")"."";
@@ -1532,6 +1532,46 @@
return $top10;
}
+ /**
+ * Calculates the age in years, months or days between now and the
+ * given values and returns an age string.
+ *
+ * @param integer $day Day
+ * @param integer $month Month
+ * @param integer $year Year
+ *
+ * @return string
+ */
+ protected function getAgeString($day, $month, $year)
+ {
+ // To be even more exact you could also at the time of birth
+ // to the calculation
+ $birthDate = new DateTime(
+ sprintf(
+ '%d-%02d-%02d',
+ (int) $year,
+ (int) $month,
+ (int) $day
+ )
+ );
+
+ $diff = $birthDate->diff(new DateTime());
+ $ageInYears = $diff->y;
+ $ageInMonths = $diff->m + (12 * $diff->y);
+ $ageInDays = $diff->days;
+
+ if ($ageInYears > 0) {
+ // Return age in years
+ return $ageInYears . 'y';
+ } elseif ($ageInMonths > 0) {
+ // Return age in months
+ return $ageInMonths . 'm';
+ }
+
+ // Return age in days
+ return $ageInDays . 'd';
+ }
+
function _averageLifespanQuery($sex='BOTH', $show_years=false) {
if ($sex == 'F') {
$sex_search = " AND i_sex='F' ";