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

Allow times which span over midnight #32

Closed klada closed 5 years ago

klada commented 5 years ago

When using the example from the OSM documentation, which has times spanning over midnight, I am getting an exception:

>>> import humanized_opening_hours as hoh
>>> hoh.OHParser("Su-Tu 11:00-01:00, We-Th 11:00-03:00, Fr 11:00-06:00, Sa 11:00-07:00")
Traceback (most recent call last):
  File "/tmp/osm/lib/python3.7/site-packages/humanized_opening_hours/main.py", line 91, in __init__
    self._tree = field_parser.parse_field(self.sanitized_field)
  File "/tmp/osm/lib/python3.7/site-packages/humanized_opening_hours/field_parser.py", line 267, in parse_field
    tree = PARSER.parse(field)
  File "/tmp/osm/lib/python3.7/site-packages/lark/lark.py", line 292, in parse
    return self.parser.parse(text)
  File "/tmp/osm/lib/python3.7/site-packages/lark/parser_frontends.py", line 79, in parse
    return self.parser.parse(token_stream, *[sps] if sps is not NotImplemented else [])
  File "/tmp/osm/lib/python3.7/site-packages/lark/parsers/lalr_parser.py", line 36, in parse
    return self.parser.parse(*args)
  File "/tmp/osm/lib/python3.7/site-packages/lark/parsers/lalr_parser.py", line 92, in parse
    reduce(arg)
  File "/tmp/osm/lib/python3.7/site-packages/lark/parsers/lalr_parser.py", line 73, in reduce
    value = self.callbacks[rule](s)
  File "/tmp/osm/lib/python3.7/site-packages/humanized_opening_hours/field_parser.py", line 174, in field_part
    "The field contains a period which spans "
humanized_opening_hours.exceptions.SpanOverMidnight: The field contains a period which spans over midnight, which not yet supported.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/osm/lib/python3.7/site-packages/humanized_opening_hours/main.py", line 92, in __init__
    except lark.lexer.UnexpectedInput as e:
AttributeError: module 'lark.lexer' has no attribute 'UnexpectedInput'

It seems like spanning over midnight is already detected, but currently not handled.

klada commented 5 years ago

I have just tested the Alpha version and it works! Sorry for the noise.

rezemika commented 5 years ago

No problem! However, you should be warned that I'm very busy these times, so I cannot guarantee to maintain and improve this module for the long term (sorry)...