rezemika / humanized_opening_hours

A parser for the opening_hours fields from OpenStreetMap
GNU Affero General Public License v3.0
26 stars 20 forks source link

MonthDayRange over 2 implicit years #26

Closed jbgriesner closed 5 years ago

jbgriesner commented 5 years ago

The opening hours of this place are:

Oct-Mar 07:30-19:30; Apr-Sep 07:00-21:00

It means that the 30th of november at 14h30 it should be open. However:

>>> oh = hoh.OHParser('Oct-Mar 07:30-19:30; Apr-Sep 07:00-21:00')
>>> oh.is_open()
False

Now if I add the year as your grammar allows it, then it works as expected:

>>> oh = hoh.OHParser('2018 Oct - 2019 Mar 07:30-19:30; Apr-Sep 07:00-21:00')
>>> oh.is_open()
True

The problem appears when the MonthDayRange spans between two different years without the explicit information in the monthday_date_month.

Do you have a solution to this problem ?

Thanks!

rezemika commented 5 years ago

Thank you for your feedback!

It's fixed by the commit 20e1bad, and I just sent the update to PyPi. You can update your version to 1.0.0b3. ;)

jbgriesner commented 5 years ago

Thanks for your fast answer!

However your fix seems not perfect yet: indeed if you add to your test different months starting from the "next" year it fails:

>>> oh = OHParser("Oct-Mar 07:30-19:30; Apr-Sep 07:00-21:00")
>>> oh.is_open(datetime.datetime(2019, 1, 1, 12, 30))   # 1st Jan: it should be open...
False
>>> oh.is_open(datetime.datetime(2019, 2, 1, 12, 30))   # 1st Feb: it should be open...
False
>>> oh.is_open(datetime.datetime(2019, 3, 1, 12, 30))   # 1st March: it should be open...
False

This is due to the 52 weeks shift of the current year, which makes the "query date" outside of the opening hours limits.

rezemika commented 5 years ago

Well, you're right. However, I don't see how to fix this properly (sorry)... Do you have any suggestion?

jbgriesner commented 5 years ago

Please find my suggestion in PR https://github.com/rezemika/humanized_opening_hours/pull/27

I think it should fix these tricky cases