simonpoole / OpeningHoursParser

Parser for string values according to the OSM opening hours specification
MIT License
32 stars 12 forks source link

Don't allow negative "nth" specifications in "nth" ranges #68

Open simonpoole opened 3 years ago

simonpoole commented 3 years ago

Does allowing this make any sense? If it does it should definitely throw an exception in strict mode.

westnordost commented 2 years ago

I can't think of any real case where this made sense, i.e. I can't think of an opening hours sign that could be written that way...

"We are open each month until and including the 30th but only every 2nd day"

If negative "nth" actually appear in the wild, I think the chance is higher that it is a typo rather than what the contributor meant.

However, a less ludicrous opening hours sign may say

"open on odd dates, i.e. every 1st, 3rd etc of each month"

If I understood the specification correctly, writing Jan-Dec 1-31/2 is not valid because month ranges are not supported at that spot. But maybe this is something that may be worth supporting in non-strict mode if it isn't yet, I don't have numbers how often this appears in the wild but there are street signs that are valid every second day of each month, see https://wiki.openstreetmap.org/wiki/Proposed_features/Parking_lane_conditionals#Other_signage

simonpoole commented 2 years ago

However, a less ludicrous opening hours sign may say

"open on odd dates, i.e. every 1st, 3rd etc of each month"

If I understood the specification correctly, writing Jan-Dec 1-31/2 is not valid because month ranges are not supported at that spot. But maybe this is something that may be worth supporting in non-strict mode if it isn't yet, I don't have numbers how often this appears in the wild but there are street signs that are valid every second day of each month, see https://wiki.openstreetmap.org/wiki/Proposed_features/Parking_lane_conditionals#Other_signage

There are two issues: on the one hand there are no month day ranges that are separate from dates. What is supported is only Jan 1-31 which simply is short hand for Jan 1 - Jan 31, so support would require month day ranges as an independent construct. Not sure if that wouldn't create even more ambiguity in parsing (for example with that shorthand). The 2nd minor issue is adding an interval specification, that is unlikely to be problematic on it's own.

westnordost commented 2 years ago

I don't see how Jan-Dec 1-31/2 would be ambiguous. Maybe in that there is no 31st of February? But anyway, I'll create a new issue for this to no longer hijack this issue about support for negative nth ranges.

westnordost commented 9 months ago

Anyway, regarding this topic, for reference, the specification also does not allow negative nth specifications in ranges. E.g. -3--1 or -2-1 should not be valid:

image https://wiki.openstreetmap.org/wiki/Key:opening_hours/specification#nth_entry