andy-z / ged4py

GEDCOM tools for Python
MIT License
18 stars 7 forks source link

Improve handling of incorrect dates #30

Closed andy-z closed 3 years ago

andy-z commented 4 years ago

Some dates, which are probably incorrect, cause exceptions in ged4py, e.g. the date:

2 DATE 29 FEB 1634/35

(this comes from ged4py_testdata/data/webtreeprint/pres.ged)

causes this exception:

Traceback (most recent call last):
  File "/home/salnikov/project-ged/ged2doc/ged2doc/cli.py", line 296, in main
    writer.save()
  File "/home/salnikov/project-ged/ged2doc/ged2doc/writer.py", line 207, in save
    events = self._events(person)
  File "/home/salnikov/project-ged/ged2doc/ged2doc/writer.py", line 344, in _events
    for date, facts in sorted(events, key=_date_key):
  File "/home/salnikov/project-ged/ged4py/ged4py/date.py", line 227, in __lt__
    return self.key() < other.key()
  File "/home/salnikov/project-ged/ged4py/ged4py/calendar.py", line 287, in __eq__
    return self.key() == other.key()
  File "/home/salnikov/project-ged/ged4py/ged4py/calendar.py", line 377, in key
    jd = convertdate.gregorian.to_jd(year, month, day) - offset
  File "/home/salnikov/venv-3.8/lib/python3.8/site-packages/convertdate/gregorian.py", line 61, in to_jd
    legal_date(year, month, day)
  File "/home/salnikov/venv-3.8/lib/python3.8/site-packages/convertdate/gregorian.py", line 37, in legal_date
    raise ValueError("Month {} doesn't have a day {}".format(month, day))
ValueError: Month 2 doesn't have a day 29

Would be nice to find some reasonable way to handle this situation.

andy-z commented 3 years ago

33 should fix the issue.