opening-hours-rs icon indicating copy to clipboard operation
opening-hours-rs copied to clipboard

Handling of spaces

Open mikael-epigram opened this issue 3 years ago • 3 comments

When attempting to run the following code:

from opening_hours import OpeningHours
s = "Apr 1 - Nov 3 00:00-24:00; PH off"
oh = OpeningHours(s)

I get the following SyntaxError:

SyntaxError: could not parse expression:
 --> 1:8
  |
1 | Apr 1 - Nov 3 00:00-24:00; PH off
  |        ^---
  |
  = expected positive_number

If I attempt to run the same string through a osm validator (https://openingh.openstreetmap.de/evaluation_tool/) the parsing goes through.

When spacing around the hyphen is removed the in the example, the string is correctly passed.

mikael-epigram avatar Jun 27 '22 15:06 mikael-epigram

Hi! Thanks for your feedback!

The reason behind that is that I tried to stick as much as possible as the specification that can be found in the wiki, which is very restrictive. The website you are referring to is using the JS implementation which appears to be the reference and has many extra features.

Sticking to the wiki is not a fatality and I think it wouldn't be too hard to modify the grammar here.

I haven't put many efforts in this project recently, mostly because I didn't have many practical usecase to it, out of curiosity were you considering using this?

remi-dupre avatar Jun 28 '22 06:06 remi-dupre

I understand.

I find that the wiki is somewhat ambiguous on the use of spaces as shown in the wiki discussion, while on wikipedia they also write "code is either written literally as such (including a literal space separator where needed; elsewhere spaces in the syntax are only for its presentation)".

I agree with you that not having space between the dates is the canonical approach.

I'm coming at this from a validation perspective. I want to parse opening hours data from separate sources and want to ensure that they conform to the standard. As such, I was looking for a Python library to handle the validation. Yours is the one I found to have the most suitable API.

mikael-epigram avatar Jun 28 '22 09:06 mikael-epigram

I've allowed your specific example in the syntax, but no more. However I feel like it would be a good idea to extend it even more but maybe still by doing some cherry picking.

The specification has indeed proved to have many ambiguities so I'm afraid to break things by adding too much. It would probably be OK with some testing, but as I haven't spent much time on this project lately I was not feeling confortable enough to do more right away.

remi-dupre avatar Aug 06 '22 09:08 remi-dupre