spatie / opening-hours

Query and format a set of opening hours

Home Page:https://freek.dev/595-managing-opening-hours-with-php

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

several advanced features

mgrundkoetter opened this issue · comments

We have customer input from another software that looks like this:

week 01-51/2 Sa 08:00-12:00; Mo 11:30-17:00; Tu 11:30-18:00; Dec 23-31 off; Jan 24 off; Oct 10 off; PH off; Apr 16 off

which opens up some questions after reading your docs.

  1. I could not find a way to input a structure like week 01-51/2 Sa 08:00-12:00; (open Saturdays on every other week 8-12) Is this possible somehow?
  2. Do you recommend a certain (dynamic) way of integration of actual holiday dates (PH off = Public Holidays)?
  3. Is there an option to directly feed an OSM string like the example one into the library without the need to convert into the array structure?

I just wanted to ask those questions together in one ticket before making more detailed feature requests, because maybe I just missed those things in the docs and they already work. If those can be future features, I can file separate issues with links to the specs and so on (please let me know).

commented
  1. I don't get this syntax neither what you mean by "other week"
  2. Days off can simply be added using exceptions as per the first example of the README (you can get the list of days from some ICS file or some API https://dev.to/monfernape/get-country-holidays-using-google-calendar-api-3dh6), you can also check business-time which work with Carbon (a sub-class of DateTime) and provide holiday lists for many countries.
  3. No. Users of this libraries have very various input formats. We won't bloat the library with multiple parsers. I can't find neither any spec for "OSM" schedule string format. You would need to find a dedicated PHP parser for this. We could add links to the readme for adapters from well-known formats, but I would not add them directly in the library.
  1. "every other" means not every, but every second or "alternating". So "week 01-51/2" would mean "open Saturdays on every second week 8-12". See example 8 at https://wiki.openstreetmap.org/wiki/Key:opening_hours#Examples and the explanation there. They also have a very nice evaluation tool for trying out more complex features: https://openingh.openstreetmap.de/evaluation_tool/
  2. Thank you, I was looking for an API like this!
  3. The specs are described at https://wiki.openstreetmap.org/wiki/Key:opening_hours#Summary_syntax in a short way and on https://wiki.openstreetmap.org/wiki/Key:opening_hours/specification with many more details. Initially I thought you build the lib based on this, but it obviously is not. As we get the opening hours in this OpenStreetMap format from our customer in this project, I was searching for a lib in PHP that can handle it, but I did not find anything except your library, which seems to be very close to this format :-) So yes, if our customer is going to pay for it, we will create a parser for this format. (There are 2 links on the OSM page pointing to PHP code which is quite outdated and, by far, does not include all the features from the specs. I will let you know if we get funds for such a parser, but I guess this issue can be closed for now.

@kylekatarnls I have started a little library for parsing OSM strings into your format: https://github.com/ujamii/osm-opening-hours
Not everything is supported yet, but it works for the requirements in my project for now. If you have time, please take a look. The information about the odd/even weeks is already parsed and added as data for now but it is not yet handled when evaluating isOpen and so on. This could also be solved by filters, but that would cost more performance than having such data settings for each item.

commented

Thanks. 🙏 Do you approve this way to promote it?
https://github.com/spatie/opening-hours/pull/190/files