* src/ReportUtils.py (old_calc_age): Correct the logic.

svn: r5941
This commit is contained in:
Alex Roitman
2006-02-15 18:26:50 +00:00
parent cb0ca84064
commit 7309f0234a
2 changed files with 49 additions and 16 deletions

View File

@@ -1,3 +1,6 @@
2006-02-15 Alex Roitman <shura@gramps-project.org>
* src/ReportUtils.py (old_calc_age): Correct the logic.
2006-02-14 Don Allingham <don@gramps-project.org>
* src/plugins/NavWebPage.py: include more information about CC licenses
in the ALT and TITLE tags.

View File

@@ -1,7 +1,7 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2005 Donald N. Allingham
# Copyright (C) 2000-2006 Donald N. Allingham
#
#
# This program is free software; you can redistribute it and/or modify
@@ -2119,8 +2119,11 @@ def old_calc_age(database,person):
months: 2
days: 3
"""
YEARS = 1
MONTHS = 2
DAYS = 3
# This is an old and ugly implementation.
# FIXME: This is an old and ugly implementation.
# It must be changed to use the new age calculator.
age = 0
units = 0
@@ -2138,23 +2141,50 @@ def old_calc_age(database,person):
else:
death_year_valid = None
if birth_year_valid and death_year_valid:
age = death.get_year() - birth.get_year()
units = 1 # year
# wihtout at least a year for each event we're clueless
if not (birth_year_valid and death_year_valid):
return (age,units)
# FIXME: The code below uses hard-coded 31 days in a month
# and 12 month in a year. This is incorrect for half the Gregorian
# months and for other calendars.
# FIXME: We need to move to estimate_age !!!
# If born and died in the same year, go to the months
if death.get_year() == birth.get_year():
if birth.get_month_valid() and death.get_month_valid():
# if born and died in the same month, do the days
if birth.get_month() == death.get_month() \
and birth.get_day_valid() and death.get_day_valid():
age = death.get_day() - birth.get_day()
units = DAYS
# if not the same month, just diff the months
else:
age = death.get_month() - birth.get_month()
units = MONTHS
# Born and died in different years
else:
age = death.get_year() - birth.get_year()
units = YEARS
if birth.get_month_valid() and death.get_month_valid():
# Subtract one year if less than a last full year
if birth.get_month() > death.get_month():
age = age - 1
if birth.get_day_valid() and death.get_day_valid():
if birth.get_month() == death.get_month() and birth.get_day() > death.get_day():
age = age - 1
if age == 0:
age = death.get_month() - birth.get_month() # calc age in months
if birth.get_day() > death.get_day():
age = age - 1
units = 2 # month
if age == 0:
age = death.get_day() + 31 - birth.get_day() # calc age in days
units = 3 # day
# If less than a year (but still in different years)
# then calculate month diff modulo 12
if age == 0:
age = 12 + death.get_month() - birth.get_month()
units = MONTHS
# This is the case of birth on Dec 30 and death on Jan 2
# or birth on May 30 and death on June 2
if age == 1 and units == MONTHS \
and birth.get_day_valid() and death.get_day_valid() \
and birth.get_day() > death.get_day():
age = death.get_day() + 31 - birth.get_day()
unit = DAYS
return (age,units)