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

Feature : get open intervals #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Mziserman
Copy link
Contributor

No description provided.

Copy link
Contributor

@berkes berkes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edit: I noticed some new issues with my implementation. Working on it now.

There is a bug in this implementation. I cannot pinpoint it exactly, as I have a hard time following all the loops.

The bug resulted in day "6" getting several additional entries. I presume the reindexing causes that, but cannot entirely confirm.

So I greatly simplified your implementation by using Ruby-isms (chains) rather than nested looping.
This suits my needs, and fixes the bug, bu may have some details omitted, I'm not too confident, yet.

     def get_open_intervals(opening_hours_string, from, to)
        date_ranges = OpeningHoursConverter::OpeningHoursParser.new.parse(opening_hours_string)

        intervals = get_time_iterator(date_ranges).select do |interval|
          interval[:start] >= from && interval[:end] <= to
        end

        intervals.map { |interval| [interval[:start].wday, interval] }.to_h
      end

Note that this will use the Ruby default of indexing weeks with Sunday being 0 rather than your implementation that has Monday as 0.

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

Successfully merging this pull request may close these issues.

2 participants