Publidata / opening_hours_converter

OpenStreetMap Opening Hours to Date & Date to Opening Hours
https://rubygems.org/gems/opening_hours_converter
GNU Affero General Public License v3.0
12 stars 3 forks source link

Support: How to get a list, for a specific week, with per-day intervals. #28

Open berkes opened 5 years ago

berkes commented 5 years ago

I'm not sure where else to ask this, sorry if an issue is not the right place.

I am, however, looking for a feature similar to opening-hours.js getOpenIntervals(to, from).

The end-result I am looking for, is a table (hash) that shows, for the current week, per-day, what either the intervals are, or per-minute arrays. Both would work for me.

My current node.js API returns the following, and I am trying to replace that node.js server app with a ruby server app (sinatra etc).

Given, the opening-hours string Mo-Fr 10:00-12:30,13:00-18:30; Sa 10:00-13:00; Su 12:00-17:00 "Shopping Sundays"

And today is 1989-11-07. So this week starts on monday 1989-11-06 and ends on sunday 1989-11-12.

Then I want, approximately the following JSON (hash structure) outputted:

     "open_this_week" : {
        0 =>[ {
           "from" : "1989-11-06T09:00:00.000Z",
           "to" : "1989-11-06T12:30:00.000Z",
           "unknown" : false
        },
        {
           "from" : "1989-11-06T13:00:00.000Z",
           "to" : "1989-11-06T18:30:00.000Z",
           "unknown" : false
        } ],
        1 =>[ {
           "from" : "1989-11-07T09:00:00.000Z",
           "to" : "1989-11-07T12:30:00.000Z",
           "unknown" : false
        },
        {
           "from" : "1989-11-07T13:00:00.000Z",
           "to" : "1989-11-07T18:30:00.000Z",
           "unknown" : false
        } ],
        2 =>[ {
           "from" : "1989-11-08T09:00:00.000Z",
           "to" : "1989-11-08T12:30:00.000Z",
           "unknown" : false
        },
        {
           "from" : "1989-11-08T13:00:00.000Z",
           "to" : "1989-11-08T18:30:00.000Z",
           "unknown" : false
        } ],
        3 =>[ {
           "from" : "1989-11-09T09:00:00.000Z",
           "to" : "1989-11-09T12:30:00.000Z",
           "unknown" : false
        },
        {
           "from" : "1989-11-09T13:00:00.000Z",
           "to" : "1989-11-09T18:30:00.000Z",
           "unknown" : false
        } ],
        4 =>[ {
           "from" : "1989-11-10T09:00:00.000Z",
           "to" : "1989-11-10T12:30:00.000Z",
           "unknown" : false
        },
        {
           "from" : "1989-11-10T13:00:00.000Z",
           "to" : "1989-11-10T18:30:00.000Z",
           "unknown" : false
        } ],
        5 => {
           "to" : "1989-11-11T13:00:00.000Z",
           "unknown" : false,
           "from" : "1989-11-11T10:00:00.000Z"
        },
        6 => {
           "comment" : "Shopping Sunday",
           "to" : "1989-11-12T17:00:00.000Z",
           "unknown" : false,
           "from" : "1989-11-12T12:00:00.000Z"
        }
     ],

So, basically: a Hash, with, per day, when it will be open. As said, i don't really mind if it has, per day, a list of the intervals (as in the above example) or if it has, per day, an array with per-minute true | false.

I manage to get typical_weeks out of this Ruby gem, but not a week given a specific date: in several occasions, that might be different. I also don't really care about PH just yet.

If you can help me on the way, I would be grateful. And will pay back with documenting the parts that I then understand in a PR :smile:

Mziserman commented 5 years ago

Hey,

I made a quick implementation on https://github.com/Publidata/opening_hours_converter/pull/29 It's probably a very inneficient way to do it, I'll have to work more on it. It's pretty much what you ask for except for the comment and the unknown since both those information are lost in https://github.com/Publidata/opening_hours_converter/blob/master/lib/opening_hours_converter/iterator.rb#L8.

If you can help me on the way, I would be grateful. And will pay back with documenting the parts that I then understand in a PR 😄

That would be awesome !