opening-hours / opening_hours.js

Library to parse and process the opening_hours tag from OpenStreetMap data
https://openingh.ypid.de/evaluation_tool/
218 stars 118 forks source link

[Feature] getHumanReadable(from, to, {options}) #234

Open homersimpsons opened 7 years ago

homersimpsons commented 7 years ago

Hello,

First of all thank ou for this awesome module :) I didn't find out any concern about this feature. I would like to know if it's possible to convert the openingHoursString to a human readable string. For example: Mo-Fr 10:00-18:00 to Monday to Friday from 10:00 to 18:00 (this is a really basic example)

Why the from and to ? This is to limit the string to bounds, will mainly be used to describe weeks I think, or current day.

In {options} there could be some configuration option like:

I think that this can be a really usefull feature in order to displa opening_hours

Let me know if you need any other informations :)

ypid commented 7 years ago

Would be interesting. But I expect this to get difficult with more advanced values. Give it a try if you need it. I think i18n should use the moment lib first or other means of localization which opening_hours.js already uses.

homersimpsons commented 7 years ago

@ypid Is there already a function to limit a opening_hours tag beetween 2 dates ? for example Mo-Fr 12:00-14:00; Feb 26 off -> Mo-Fr 12:00-14:00 if I have from = 1 March; to = 1 April ?

ypid commented 7 years ago

Kind of. The main purpose of this lib is to evaluate oh values like Mo-Fr 12:00-14:00; Feb 26 off down to the actual opening hours for a given time. The intermediate/internal formats don’t work as would be useful for your case. You might be able to iterate over all changes for your from and to and call oh.getMatchingRule to get all rules which apply, then assemble them back and make them human readable.

First of all thank ou for this awesome module :)

You are welcome. Nice that you like it :)

HolgerJeromin commented 7 years ago

Fyi: Osmand has a Translation of the days into the current language. This is a baby step to a human readable string

ypid commented 7 years ago

Thanks for the hint with OsmAnd 👍 This lib can also do it :)

make them human readable.

I should probably mention oh.prettifyValue which already goes into the direction of getHumanReadable. It can be configured to be more human friendly (that is what the evaluation tool does, see "prettified opening_hours value for displaying", also hyperlinked to the spec and all that good stuff).

oh.prettifySelector could be used as a reference to translate tokens (parts of the original input value) and reformat the output.

Refs:

thany commented 6 years ago

Sorry for the bump, but I'm interested in this as well.

Would be possible to limit getHumanReadble to fairly simple expressions, and build it out later? In my mind, something like this:

Mo-Sa 10:00-20:00; Tu off; Dec off

Might become:

Open Monday to Saturday 10:00-20:00
Closed on Tuesdays, and during December

So it's basically summing up the open and close times.

Another one, just for kicks:

Apr-Oct 9:00-17:30; Jul-Aug 9:00-21:00; PH off; Mo off

Becomes

Open 9:00-17:30 during April to October
Open 9:00-21:00 during July and August
Closed on public holidays and mondays

So this indicates, again, just summing it up. I wouldn't expect it to calculate the months it's closed, nor would I expect it to spell out all the public holidays. I also wouldn't expect it to cleverly handle the overlap in months.

All-day openings:

24/7; Jan 1 off

Becomes:

Open 24/7
Closed on January 1

Another:

Mo-Fr 0:00-24:00; Sa-Su 4:00-22:00

Becomes:

Open Monday to Friday 24 hours
Open Saturday and Sunday 4:00-22:00

I think this should be quite doable. And just ignore complex expressions for now. Like easter -2 days, who even does that? :)

I'm gonna have a lot of fun with this if this function became available :D

ypid commented 6 years ago

Hey @thany

I'm gonna have a lot of fun with this if this function became available :D

It does not just become available ;-) See the milestone it has been assigned by me. So if not somebody else steps in and implements it (see my comment above where I gave some input how this can be done) then there is no roadmap at all when this will be available/done by me if ever.

Like easter -2 days, who even does that? :)

OSM mappers use it, for which this project is for ;-)