scrapinghub / dateparser

python parser for human readable dates
BSD 3-Clause "New" or "Revised" License
2.55k stars 465 forks source link

STRICT_PARSING use #828

Open kutera opened 3 years ago

kutera commented 3 years ago

BHello, The STRICT_PARSING use is not so easy to understand. Example with release 1.0.0

parse('90 days',settings={'STRICT_PARSING':True}) Result: datetime.datetime(2020, 8, 3, 16, 24, 8, 599042)

Same issue with search :

search.search_dates('90 days',settings={'STRICT_PARSING':True}) result: [('90 days', datetime.datetime(2020, 8, 3, 16, 27, 8, 382830))]

I expected None result Or is it another solution to avoid relative date results ? Only if day, month and year are found.

Best Regards

Gallaecio commented 3 years ago

Well, you can use the PARSERS setting to disable the relative parser.

Whether STRICT_PARSING should have prevented this to work, I’m unsure, although I’m slightly inclined towards your interpretation (if there is no year or month set explicitly and STRICT_PARSING is True, no date should be parsed).

kutera commented 3 years ago

Thanks, this workaround solved my cases.
I added REQUIRE_PARTS too.

search.search_dates('90 days',settings={'REQUIRE_PARTS': ['day', 'month', 'year'], 'PARSERS':['absolute-time',]})

noviluni commented 3 years ago

As part of the last point here: https://github.com/scrapinghub/dateparser/issues/796 (which I'm working on), I will add notes in the docs regarding what parser are affected by each setting.