9799: Use latest valid date rather than today

This is useful for historic places when an event date is not
available.
This commit is contained in:
Nick Hall 2016-12-09 19:22:46 +00:00
parent 772265c3ef
commit 5621ade2e4

View File

@ -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