Streetcomplete: Discussion: syntax of opening_hours (rule separators)

Created on 8 Jun 2017  ·  25Comments  ·  Source: westnordost/StreetComplete

I noticed that the quest for opening_hours currently separates the rules for different days by a comma (,) where they actually should be separated by a semicolon (;). A comma separates different time spans within _one rule_ (such as _Mo-Fr 08:00-13:00, 15:00-18:00_) but for different rules on different days, the semicolon is compulsory (such as _Mo 08:00-18:00; Tu 09:00-17:00_)

Right now, this causes problems in apps like OsmAnd. I added very many opening_hours just recently using StreetComplete and I had to correct all of them manually.

PS: I'm using version 0.11 of StreetComplete right now.

Most helpful comment

The repository of YoHours is here : https://framagit.org/PanierAvide/YoHours
The interesting class is OpeningHoursBuilder, which takes some date ranges and generates the opening_hours string. The project was heavily tested, however some tricky cases remains and output is not always as concise as possible.

All 25 comments

See https://github.com/westnordost/StreetComplete/issues/108#issuecomment-299657127

StreetComplete actually used the semikolon before, but it turned out that was wrong.

There's clearly a problem here:

The evaluation tool claims that
Mo 10:00-18:00, Tu 09:00-17:00
is exactly identical to
Mo 10:00-18:00; Tu 09:00-17:00

However, this is not correct. The syntax description in the OSM wiki is very clear about the use of comma and semicolon (unfortunately, only in the German translation):

  • einzelne Tage getrennt durch "," · ( z. B.> Mo,We,Fr )
  • einzelne Stundenbereiche getrennt durch "," · ( z. B.> 8:30-14:00,16:30-20:00 )
  • verschiedene Stunden an verschiedenen Tagen werden getrennt durch ";" ( z. B.> Mo 10:00-12:00,12:30-15:00; Tu-Fr 08:00-12:00,12:30-15:00;)

This means that _different rules for different days_ are always separated by semicolon while _different times ranges within one rule_ are separated by comma.

As I said, I added about 60 opening_hours during last month. When they were included in the latest version of OsmAnd map data, the app couldn't handle the comma separated values for different days correctly. Here's what happend:
20170608223057_screenshot_20170608-222629

Printed in black is the literal content of the opening_hours tag. This is what was added by StreetComplete. Marked in red is how OsmAnd interpreted that data. Note how "Sa" for Saturday was neglected because of the comma and the second time range (10:00-15:00) was understood to also apply to the first rule (Mo-Fr).
I believe this interpretation of OsmAnd to be in exact accordance with the syntax as specified in the wiki. So the problem is actually caused by StreetComplete because of using comma instead of semicolon.

The case you referenced in #108 is different.

It is true that a semicolon will always override a previous rule if the same days are give twice. This means that opening_hours=Mo-Fr 08:30-12:30; Mo,Th 14:00-18:00; Tu,We,Fr 14:00-16:30 indeed will not work as intended (this was the example quoted in the other discussion).

As far as I see it right now, the only way to solve both those problems is to resist the temptation to summarize rules and instead split this up into as many individual rules as there are individual opening_hours on different days. So in the given example, we have two different patterns for opening hours during the week. Like this:

Mo, Th 08:30-12:30, 14:00-18:00
Tu, We, Fr 08:30-12:30, 14:00-16:30

I realize this double-records the entry for morning hours. But it seems to me that this is the only way to be safe in every direction.

Apparently this needs some clarification.

However, this is not correct. The syntax description in the OSM wiki is very clear about the use of comma and semicolon (unfortunately, only in the German translation):

Translations should be translations and not reinterpretations.

Only because OsmAnd is not able to interpret the opening hours following the specification doesn't make the data incorrect.
Right now your are suggesting that OsmAnd has it implemented correctly but the Opening Hours Evaluation tool on openstreetmap.de has it implemented incorrectly. In any case, there is one program that does not have a correct implementation, it is no use as an argument that any particular program cannot correctly interpret any particular opening hours format.

The one truth is the specification here: https://wiki.openstreetmap.org/wiki/Key:opening_hours/specification . Ctrl+F for _""_

Ja - hier sollte Streetcomplete nachbessern, da es bei der Auswertung zu Fehlern führen (kann).
pictures_u1061_mtpgZIHC.jpg
Wenn man mit dem Mauszeiger auf die entsprechende Regel zeigt:
https://wiki.openstreetmap.org/wiki/DE:Key:opening_hours/specification#section:rule_separators

http://forum.openstreetmap.org/viewtopic.php?pid=650427#p650427

don't understand the problem, comma is an additional rule, semicolon is an overwriting rule. So its better to use comma for excluding special problems like

It is true that a semicolon will always override a previous rule if the same days are give twice. This means that opening_hours=Mo-Fr 08:30-12:30; Mo,Th 14:00-18:00; Tu,We,Fr 14:00-16:30 indeed will not work as intended (this was the example quoted in the other discussion).

it doesnt work because its wrong.
Another example: Mo 15:00-01:00; Tu 15:00-24:00 is wrong too.

Sorry for the late reply - have been busy recently.

I understand that it doesn't matter whether a comma (additive) or a semicolon (overwriting) is used _as long as every rule stands for a different set of days_. As soon as two or more rules are intended to apply to the same day, a comma _must_ be used. Otherwise the first rule would be overwritten.

Is this the reason you decided to use only commas? Because the normal rule separator is still a semicolon (see here: opening hours/specification) And on this the English and German wiki are definitely in accordance. :-)

I still think the best solution would be to do this:

Mo, Th 08:30-12:30, 14:00-18:00;
Tu, We, Fr 08:30-12:30, 14:00-16:30

In this example we have to different rules - one for Monday and Thursday, the other for Tuesday, Wednesday, and Friday. Time ranges are separated by comma, while rules are separated by semicolon.

I believe this is clear and precise and in accordance with every statement on the wiki and the evaluation tool. See here: Evaluation Tool

I also opened an issue at OsmAnd github project, since they clearly do not read this correctly. But if StreetComplete would follow my suggestion, we would be on the safe side under all circumstances.

@Jotam this is not the best solution, plz take a look at my example and understand it.

@dex2000: There is no need to be rude. I have read your comment but I still don't see why my proposal should not solve the problems you mention. Quite on the contrary: the syntax I suggest would solve _all_ problems that have been mentioned in this discussion.

@Jotam if you think im rude, that was nevertime my intention, sry if you understood it so.

The syntax you suggest cannot solve all problems. The syntax makes problems (like in my example)
The Comma cannot solve all problems too, but it makes much more less problems.

@dex2000 Alright, dex. The expression take a look at my example and understand it sounded a bit offensive to my ears. But that's okay then.

I see the problem with opening hours that pass midnight. According to the wiki those must indeed be noted using comma only.

I guess I just don't understand the whole point of semicolons if 'commas only' is - as you claim - the better option.

for english speaker: this is duplicate of previous post @Jotam ich sehe gerade, dass Du offenbar deutsch sprichst, ich hatte nicht vor unhöflich zu sein, sondern nur das Gefühl, dass Du nicht verstanden hast, dass man mit dem _überschreibenden_ Semikolon viel falsch machen kann, besonders, wenn das ein Automatismus generiert. Das kann man mit dem _ergänzenden_ Komma zwar auch, aber eben nicht in dem Umfang.

Problem bei beiden Varianten ist übrigens, dass eine maschinelle Generierung von maschinenlesbaren Tags keine maschinenles-/ erkennbaren Fehler "generieren" kann. Meine Beispielregel bspw. ist formal korrekt wird aber (noch) nicht von QA-Tools gefunden.

So the problem is actually caused by StreetComplete because of using comma instead of semicolon.

Only because OsmAnd is not able to interpret the opening hours following the specification doesn't make the data incorrect.

Well, technically the solution by @westnordost in https://github.com/westnordost/StreetComplete/issues/108#issuecomment-299663569 It looks like this can be solved by just concatenating the rules with "," instead of ";" because all rules specified in the UI are meant to be additive. is correct (until the day comes when support for closing rules is added …). opening_hours support in OsmAnd is a bit limited but that should not pose restrictions on StreetComplete of course. Ref: https://github.com/osmandapp/Osmand/issues/473

That said, I would recommend against using additional_rule_separator as default. This is not how it is intended. The normal_rule_separator is called normal rule separator for a reason :wink:

You might want to take a look at how http://projets.pavie.info/yohours/ does things which I have found quite nice.

I still think the best solution would be to do this:

Mo,Th 08:30-12:30,14:00-18:00;
Tu,We,Fr 08:30-12:30,14:00-16:30

[Example slightly cleaned by copying from "prettified opening_hours value for displaying" of the [opening_hours evaluation tool](http://openingh.openstreetmap.de/evaluation_tool/)]

I agree. YoHours actually generates this very same value too which means there is even source code available plus @PanierAvide, the author of YoHours is already involved in StreetComplete so I think this is the way to go.

That said, using all features of the syntax would allow a more to the point value:

Mo-Fr 08:30-12:30,
Mo,Th 14:00-18:00,
Tu,We,Fr 14:00-16:30

which I would always prefer when hand writing opening_hours. But don’t get crazy about it. Both are valid. No reason to retag one to the other. Ref: https://www.openstreetmap.org/changeset/48702644

Nope, it is not wrong. See

True, but not really future prove either. This would break with closing rules and so on.

@westnordost Can you reopen? Also, maybe https://github.com/simonpoole/OpeningHoursParser used in http://vespucci.io/ might be worth a look. There are appearing more and more apps which do similar things. To me it sounds like things should be unified into one library to create opening_hours values on Android (which would also come in handy for my app idea ComplexAlarm :wink:)

Hmm, I don't understand the big interest on which rule separator to use.

Anyway, yeah it would make sense to have _one_ Java library to parse OpeningHours, but this is nothing from which StreetComplete would profit, as StreetComplete does not parse opening hours, it only writes them.

support for closing rules is added

What do you mean? "off"? I do not really intend to implement that as the form is too complex already anyway and I do not see the gain. But if I did, the "off" rules would simply be separated from the "on" rules with one semicolon.

Anyway, yeah it would make sense to have one Java library to parse OpeningHours, but this is nothing from which StreetComplete would profit, as StreetComplete does not parse opening hours, it only writes them.

That is what I mean with "create opening_hours values". A UI for users to build opening_hours values which StreetComplete and YoHours do. You are right, actually parsing (or even interpreting/evaluating) the value is not needed.

Side node: Parsing and evaluating is actually easier (but has not been done yet) to do platform independently compared to the UI value building thingy. Ref: https://github.com/opening-hours/opening_hours.js/issues/136

I do not see the gain

Needed for "PH off" :wink: Ref: #276

But if I did, the "off" rules would simply be separated from the "on" rules with one semicolon.

That would work.

That said, I would recommend against using additional_rule_separator as default. This is not how it is intended. The normal_rule_separator is called normal rule separator for a reason

After this long and detailed discussion, I would really like to understand the reason as to why the semicolon (overwriting) is the _normal_rule_separator_.

To me it sounds like things should be unified into one library to create opening_hours values on Android

This would of course be excellent, but I don't see this happen very soon. The question to me is how we can make sure that different apps read and write opening_hours in a format that is mutually understood and accepted.

After this long and detailed discussion, I would really like to understand the reason as to why the semicolon (overwriting) is the normal_rule_separator.

The semicolon existed first and is widely used. The comma was introduced later by Netzwolf when I remember correctly. So to be honest this is just how the syntax developed. People started writing Mo-Fr 08:00-16:00; We 08:00-12:00. It could also be the other way around Mo-Fr 08:00-12:00, Mo,Tu,Th,Fr 12:00-16:00. I guess it just developed this way based on how opening hours are written at amenities and how people think about them. People can have different preferences of course. It is just that the normal_rule_separator has always been the "default" rule separator and mappers use it as such.

Practical advantages:

  • Mappers usually get away with only using the normal_rule_separator. Example: Mo-Fr 10:00-20:00; PH off.
  • opening_hours values which only use additional rules could get complicated because you would have to look at all previous rules to see if they might interfere with later rules.
  • The fact that the comma (token) is used to terminate rules and time spans at the same time might look wired (and makes implementation very difficult). This is more about the used token (comma) then what should be the default behavior.
  • (More widely supported by software). "Don’t tag for the renderer" I know.

Disadvantages:

  • Normal rules overwrite also parts of previous rules which wrap over might night: Fr 22:00-04:00; Sa 21:00-04:00 (incorrect) needs to use additional rules Fr 22:00-04:00, Sa 21:00-04:00 (correct).

So, use what fits best but if it does not matter which separator to use, just use the normal one :wink:

You are free to discuss this further and maybe create an proposal for this. The syntax is not written in stone.

Thanks for the explanation.

if it does not matter which separator to use, just use the normal one

That's what I live by. :wink:

I guess the question is: what would be a way forward to achieve the best possible level of compatibility?

Maybe http://projets.pavie.info/yohours/ could be checked out and how it does things.

The repository of YoHours is here : https://framagit.org/PanierAvide/YoHours
The interesting class is OpeningHoursBuilder, which takes some date ranges and generates the opening_hours string. The project was heavily tested, however some tricky cases remains and output is not always as concise as possible.

To me it sounds like things should be unified into one library to create opening_hours values on Android

For reference, I just found out that this exists already: https://github.com/simonpoole/OpeningHoursFragment

This opening hour editor might be a good addition to SC
https://twitter.com/sp8962/status/878370431408816129

@callis that is the same as https://github.com/simonpoole/OpeningHoursFragment 😉

Was this page helpful?
0 / 5 - 0 ratings

Related issues

HolgerJeromin picture HolgerJeromin  ·  3Comments

nmxcgeo picture nmxcgeo  ·  3Comments

RubenKelevra picture RubenKelevra  ·  4Comments

JulienPalard picture JulienPalard  ·  3Comments

MattWhilden picture MattWhilden  ·  3Comments