From d1d08a15522d279422aeae04f45798dcba2ddc00 Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Fri, 9 Dec 2016 19:22:46 +0000 Subject: [PATCH] 9799: Use latest valid date rather than today This is useful for historic places when an event date is not available. --- gramps/gen/utils/location.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/gramps/gen/utils/location.py b/gramps/gen/utils/location.py index d5d016e66..cd4feaa4b 100644 --- a/gramps/gen/utils/location.py +++ b/gramps/gen/utils/location.py @@ -21,7 +21,7 @@ """ Location utility functions """ -from ..lib.date import Today +from ..lib.date import Date, Today #------------------------------------------------------------------------- # @@ -33,7 +33,7 @@ def get_location_list(db, place, date=None, lang=''): Return a list of place names for display. """ if date is None: - date = Today() + date = __get_latest_date(place) visited = [place.handle] lines = [(__get_name(place, date, lang), place.get_type())] while True: @@ -63,6 +63,22 @@ def __get_name(place, date, lang): endonym = place_name.get_value() return endonym if endonym is not None else '?' +def __get_latest_date(place): + latest_date = None + for place_name in place.get_all_names(): + date = place_name.get_date_object() + if date.is_empty() or date.modifier == Date.MOD_AFTER: + return Today() + else: + if date.is_compound(): + date1, date2 = date.get_start_stop_range() + date = Date(*date2) + if date.modifier == Date.MOD_BEFORE: + date = date - 1 + if latest_date is None or date > latest_date: + latest_date = date + return latest_date + #------------------------------------------------------------------------- # # get_main_location