# Statistics: Age calculation wrong at "Oldest living people"

Bug #1166054 reported by Sunday on 2013-04-08
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Triaged
Wishlist
Unassigned

### Bug Description

Today (08.04.2013) is the first birthday of my son but the statistic of "Oldest living people" shows an age of 11 months for him and to the expected 12 months or at least 1 year.

Sunday (magic-sunday) on 2013-04-08
 description: updated description: updated
 ToyGuy (toyguy) wrote on 2013-04-08: #1

Where is your server located? Is it possibly in a different time zone?

 Changed in webtrees: status: New → Incomplete
 Sunday (magic-sunday) wrote on 2013-04-08: #2

The server is on my NAS. There is no time zone difference.

Sunday (magic-sunday) on 2013-04-08
 Changed in webtrees: status: Incomplete → New
 Sunday (magic-sunday) wrote on 2013-04-08: #3

The age calculation inside _topTenOldestAlive is wrong. As the age in days is 365 but the calculation is by dividing through 365.25 (i think because of leap years) the final result is less than 1 so the age is 11months not 1 year as it should be.

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';
}

 fisharebest (fisharebest) wrote on 2013-04-08: #4

webtrees works with a number of different calendars.

One's age can be different, depending on which calendar one uses. It is possible for someone to be 51 years old (gregorian), 52 years old (jewish) and 53 years old (arabic) at the same time.

Hence you may have someone aged 52 who is older than someone who is aged 53 (!)

The calendar calculations are quite complex, and hence quite slow.

The statistics make a number of simplications to allow them to improve performance. The "solar year" approximation is one of them. You'll see it throughout the Stats.php module.

In this particular case, it should be possible to calculate the "calendar" age (rather than the solar-year age"), as this is done after the "heavy lifting" part.

 Changed in webtrees: importance: Undecided → Wishlist status: New → Triaged
 Sunday (magic-sunday) wrote on 2013-04-08: #5

I added a possible patch for the Stats.php to fix the calculation.

 fisharebest (fisharebest) wrote on 2013-04-08: #6

The patch uses hard-coded rules for gregorian calendars (e.g. 12 months in a year). The jewish calendar can have 13 months in some years.

Any solution will need to use the existing calendar library functions.

 kiwi (kiwi3685-deactivatedaccount) wrote on 2013-04-08: #7

I don't believe it is necessary to "fix" this.

Statistics are only ever meant to be an approximation, not an exact measure. The more accurate you try to make them, the more problems you create.

The example quoted in this bug report is a rare / uncommon situation. I can't imagine many family trees where the oldest living individual is (about) 1 yr old.

I recommend the status of this bug be changed to either "invalid" or "will not fix".

(By the way, I not that "sunday" / "sonntag" posted the same "bug" on the PGV bug list. That will, if responded to at all, get the same answer, as the code is or was identical).

 Sunday (magic-sunday) wrote on 2013-04-10: #8

As its a bug it should be fixed. Sure its not a big bug and there is maybe a lot of other stuff to be done.

The problem exists for nearly everyone:
19 year old person * 365 days per year + appr. 4 leap year days = 18,99794 => Display: 18y

 wooc (wooc) wrote on 2013-04-10: #9

Sunday as you can see in #3 the age (\$age) is in days. The bug NOT exists for nearly everyone. You can see it only on a specific day (probably birthday) and, I think, only once in 4 years period. So the bug exists extremely rarely.