charliermarsh / semantic

A Python library for extracting semantic information from text, such as dates and numbers.
MIT License
74 stars 20 forks source link

extractDate wrong year extracted #10

Closed fabiocaccamo closed 3 years ago

fabiocaccamo commented 8 years ago

You can test this bug by extracting the date from the following string: "Instagram photo by @xxxx • Oct 3, 2015 at 2:16am UTC"

As you can see the year is wrong, it should extract 2015 instead of 2016.

Thanks for this great lib.

fabiocaccamo commented 8 years ago

This is my current workaround:

date_service = DateService()
date_obj = date_service.extractDate(date_str)
now = datetime.now()
years = list(reversed(range(1990, now.year)))
for year in years:
    year_str = str(year)
    if year_str in date_str:
        date_obj = date_obj.replace(year=year)
        break;

Could you fix it please?