Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
berkes opened this issue Jul 25, 2019 · 1 comment
Open

Comments

@berkes
Copy link
Contributor

berkes commented Jul 25, 2019

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 😄

@Mziserman
Copy link
Contributor

Mziserman commented Jul 25, 2019

Hey,

I made a quick implementation on #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 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants