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

Wrong first day of week #20

Closed GioBonvi closed 5 years ago

GioBonvi commented 5 years ago

As stated in #17 when running the basic example found at the beginning of README

>>> import humanized_opening_hours as hoh
>>> field = "Mo-Fr 06:00-21:00; Sa,Su 08:00-12:00"
>>> oh = hoh.OHParser(field, locale="en")
>>> oh.is_open()
True
>>> oh.next_change()
datetime.datetime(2017, 12, 24, 12, 0)
>>> print('\n'.join(oh.description()))
"""
From Monday to Friday: 6:00 AM – 9:00 PM.
From Saturday to Sunday: 8:00 AM – 12:00 PM.
"""

I get a completely different result:

>>> import humanized_opening_hours as hoh
>>> field = "Mo-Fr 06:00-21:00; Sa,Su 08:00-12:00"
>>> oh = hoh.OHParser(field, locale="en")
>>> print('\n'.join(oh.description()))
From Sunday to Thursday: 6:00 AM – 9:00 PM.
From Friday to Saturday: 8:00 AM – 12:00 PM.

I suspect this might be related to some settings, possibily regarding Python internal localization as I live in Italy.
Let me know if I can help you, for example with any details on localization settings of my Python installation (which by the way is Python 3.6.5 on Ubuntu 18.04.1 in WSL running on Windows 10).

rezemika commented 5 years ago

Thank you for your report! However, I'm quite limited by my knowledge of the internal operations of Python... But, as Hacktoberfest started, I'll see if anyone has an idea. :)

I suspect the problem come from here: https://github.com/rezemika/humanized_opening_hours/blob/master/humanized_opening_hours/main.py#L622-L638

GioBonvi commented 5 years ago

I can confirm that @amatissart fix in #24 fixed the problem for me (see outputs for both 'en' and 'it')

>>> import humanized_opening_hours as hoh
>>> print('\n'.join(hoh.OHParser("Mo-Fr 06:00-21:00; Sa,Su 08:00-12:00", locale="en").description()))
From Monday to Friday: 6:00 AM – 9:00 PM.
From Saturday to Sunday: 8:00 AM – 12:00 PM.
>>> print('\n'.join(hoh.OHParser("Mo-Fr 06:00-21:00; Sa,Su 08:00-12:00", locale="it").description()))
Da lunedì a venerdì: 06:00 - 21:00.
Da sabato a domenica: 08:00 - 12:00.
rezemika commented 5 years ago

Thank you for the feedback! I close the issue. :)