Giter VIP home page Giter VIP logo

opening_hours_converter's People

Contributors

berkes avatar guillaumj avatar juliannacci avatar martindoff avatar mziserman avatar thomasvictoria avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

opening_hours_converter's Issues

Failing test.

Test rspec ./spec/opening_hours_builder_spec.rb:463 fails.

expected: "2017 Dec 15-2018 Jan 15 00:00-03:00,10:00-24:00"
     got: "2017 Dec 15-2018 Jan 15 Mo 10:00-24:00; 2017 Dec 15-2018 Jan 15 Tu 00:00-03:00"

It looks like this test has never worked, according to git-bisect the first commit where this started failing, is the commit where it was introduced.

I'm not familiar enough with opening_hours_rule.rb yet to understand where the decision to place a ; or a , is made.

According to the specs, both are similar, just different in presentation. The first, however, is cleaner, but means the same as the last. So if it is enough to simply rewrite the test, I can do that.

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

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 ๐Ÿ˜„

test generattion

time = ['2030 10:00-20:00',
  '10:00-20:00',
  '2030 week 1 10:00-20:00',
  '2030 week 1,3 10:00-20:00',
  '2030 week 1,3,10-30 10:00-20:00',
  '2030 week 1,3,10-30/2 10:00-20:00',
  '2030 week 1,3,10-30/2,50 10:00-20:00',
  'week 1 10:00-20:00',
  'week 1,3 10:00-20:00',
  'week 1,3,10-30 10:00-20:00',
  'week 1,3,10-30/2 10:00-20:00',
  'week 1,3,10-30/2,50 10:00-20:00',
  '2030 Jan 10:00-20:00',
  '2030 Jan 1-Jun 30 10:00-20:00',
  '2030 Jan-2050 Jun 10:00-20:00',
  '2030 Jan 10-2050 Jun 30 10:00-20:00',
  '2030-2050 10:00-20:00',
  'Jan 10:00-20:00',
  'Jan 1-Jun 30 10:00-20:00',
  'Jan 10-Jun 30 10:00-20:00']

offs = ['2030 off',
  'off',
  '2030 week 1 off',
  '2030 week 1,3 off',
  '2030 week 1,3,10-30 off',
  '2030 week 1,3,10-30/2 off',
  '2030 week 1,3,10-30/2,50 off',
  'week 1 off',
  'week 1,3 off',
  'week 1,3,10-30 off',
  'week 1,3,10-30/2 off',
  'week 1,3,10-30/2,50 off',
  '2030 Jan 1-31 off',
  '2030 Jan 1-Jun 30 off',
  '2030 Jan-2050 Jun off',
  '2030 Jan 10-2050 Jun 30 off',
  '2030-2050 off',
  'Jan 1-31 off',
  'Jan 1-Jun 30 off',
  'Jan 10-Jun 30 off']

ph_offs = ['2030 PH off',
  'PH off',
  '2030 week 1 PH off',
  '2030 week 1,3 PH off',
  '2030 week 1,3,10-30 PH off',
  '2030 week 1,3,10-30/2 PH off',
  '2030 week 1,3,10-30/2,50 PH off',
  'week 1 PH off',
  'week 1,3 PH off',
  'week 1,3,10-30 PH off',
  'week 1,3,10-30/2 PH off',
  'week 1,3,10-30/2,50 PH off',
  '2030 Jan 1-31 PH off',
  '2030 Jan 1-Jun 30 PH off',
  '2030 Jan 1-2050 Jun 30 PH off',
  '2030 Jan 10-2050 Jun 30 PH off',
  '2030-2050 PH off',
  'Jan 1-31 PH off',
  'Jan 1-Jun 30 PH off',
  'Jan 10-Jun 30 PH off']

multime = ['2030 10:00-20:00,21:00-23:00',
  '10:00-20:00,21:00-23:00',
  '2030 week 1 10:00-20:00,21:00-23:00',
  '2030 week 1,3 10:00-20:00,21:00-23:00',
  '2030 week 1,3,10-30 10:00-20:00,21:00-23:00',
  '2030 week 1,3,10-30/2 10:00-20:00,21:00-23:00',
  '2030 week 1,3,10-30/2,50 10:00-20:00,21:00-23:00',
  'week 1 10:00-20:00,21:00-23:00',
  'week 1,3 10:00-20:00,21:00-23:00',
  'week 1,3,10-30 10:00-20:00,21:00-23:00',
  'week 1,3,10-30/2 10:00-20:00,21:00-23:00',
  'week 1,3,10-30/2,50 10:00-20:00,21:00-23:00',
  '2030 Jan 10:00-20:00,21:00-23:00',
  '2030 Jan 1-Jun 30 10:00-20:00,21:00-23:00',
  '2030 Jan-2050 Jun 10:00-20:00,21:00-23:00',
  '2030 Jan 10-2050 Jun 30 10:00-20:00,21:00-23:00',
  '2030-2050 10:00-20:00,21:00-23:00',
  'Jan 10:00-20:00,21:00-23:00',
  'Jan 1-Jun 30 10:00-20:00,21:00-23:00',
  'Jan 10-Jun 30 10:00-20:00,21:00-23:00']

days = ['2030 Mo-Fr 10:00-20:00,21:00-23:00',
  'Mo-Fr 10:00-20:00,21:00-23:00',
  '2030 week 1 Mo-Fr 10:00-20:00,21:00-23:00',
  '2030 week 1,3 Mo-Fr 10:00-20:00,21:00-23:00',
  '2030 week 1,3,10-30 Mo-Fr 10:00-20:00,21:00-23:00',
  '2030 week 1,3,10-30/2 Mo-Fr 10:00-20:00,21:00-23:00',
  '2030 week 1,3,10-30/2,50 Mo-Fr 10:00-20:00,21:00-23:00',
  'week 1 Mo-Fr 10:00-20:00,21:00-23:00',
  'week 1,3 Mo-Fr 10:00-20:00,21:00-23:00',
  'week 1,3,10-30 Mo-Fr 10:00-20:00,21:00-23:00',
  'week 1,3,10-30/2 Mo-Fr 10:00-20:00,21:00-23:00',
  'week 1,3,10-30/2,50 Mo-Fr 10:00-20:00,21:00-23:00',
  '2030 Jan Mo-Fr 10:00-20:00,21:00-23:00',
  '2030 Jan 1-Jun 30 Mo-Fr 10:00-20:00,21:00-23:00',
  '2030 Jan-2050 Jun Mo-Fr 10:00-20:00,21:00-23:00',
  '2030-2050 Mo-Fr 10:00-20:00,21:00-23:00',
  'Jan Mo-Fr 10:00-20:00,21:00-23:00',
  'Jan 1-Jun 30 Mo-Fr 10:00-20:00,21:00-23:00',
  'Jan 10-Jun 30 Mo-Fr 10:00-20:00,21:00-23:00']

combos = [time, offs, ph_offs, multime, days]
@products = []
combos.each_with_index do |ohs, index|
  combos.each_with_index do |combo, combo_index|
    next if index == combo_index

    @products += ohs.product(combo).map { |product| product.join('; ') }
  end
end
@products += time
@products += offs
@products += ph_offs
@products += multime
@products += days
passing = @products.select { |oh| @builder.build(@parser.parse(oh)) == oh }
not_passing = @products - passing

File.open('spec/automaticaly_generated_parser_passing_spec.rb', 'w') do |f|
  f.write("require 'opening_hours_converter'\n\nRSpec.describe OpeningHoursConverter::OpeningHoursParser, '#parse' do")
  f.write(passing.map do |oh|
    "  it \"#{oh}\" do\n    expect(OpeningHoursConverter::OpeningHoursBuilder.new.build(OpeningHoursConverter::OpeningHoursParser.new.parse('#{oh}'))).to eql('#{oh}')\n  end\n"
  end.join)
  f.write('end')
end
File.open('spec/automaticaly_generated_parser_not_passing_spec.rb', 'w') do |f|
  f.write("require 'opening_hours_converter'\n\nRSpec.describe OpeningHoursConverter::OpeningHoursParser, '#parse' do")
  f.write(not_passing.map do |oh|
    "  it \"#{oh}\" do\n    expect(OpeningHoursConverter::OpeningHoursBuilder.new.build(OpeningHoursConverter::OpeningHoursParser.new.parse('#{oh}'))).to eql('#{oh}')\n    # #{OpeningHoursConverter::OpeningHoursBuilder.new.build(OpeningHoursConverter::OpeningHoursParser.new.parse(oh))}\n  end\n"
  end.join)
  f.write('end')
end

Inconsistent selector parsing

parser = OpeningHoursConverter::OpeningHoursParser.new
builder = OpeningHoursConverter::OpeningHoursBuilder.new

builder.build(parser.parse("Apr-Jul,Sep-Nov 24/7"))
> ArgumentError: Unsupported selector Apr-Jul,Sep-Nov

builder.build(parser.parse("Apr-Jul 24/7; Sep-Nov 24/7"))
> "Apr-Jul,Sep-Nov 24/7"

Week Index

Cannot decode week index as following: Sa[1,3] or Th[1-3]

Support "late" or "until last customer" modifier.

Strings like Mo 17:00-18:00+ exist quite a lot in the OSM planet database.

This currently fails with a Token error.

  it 'Mo 17:00-18:00+' do
    expect(OpeningHoursConverter::OpeningHoursBuilder.new.build(OpeningHoursConverter::OpeningHoursParser.new.parse('Mo 17:00-18:00+'))).to eql('Mo 17:00-18:00+')
  end
  it 'Mo 17:00-18:00+ "comment"' do
    expect(OpeningHoursConverter::OpeningHoursBuilder.new.build(OpeningHoursConverter::OpeningHoursParser.new.parse('Mo 17:00-18:00+ "comment"'))).to eql('Mo 17:00-18:00+ "comment"')
  end

The Wiki:

This may be used in place of "late" or "until last customer", e.g. 12:00+.

I can fix this, and have coded some options already, but I'd like some imput first. How do you want this handled?

  1. Ignore the +.
  2. Replace it with a comment such as "late"? If so, how to deal with the second spec, where another comment exists?
  3. Raise some error. And if so, what error?

Off-by-one error in `get_as_minute_array`

Parsing a week and converting to a byte-array with get_as_minute_array results in 1441 minutes per day. A day only has 1440 minutes. I assume 00:00/24:00 are counted twice. Once as beginning minute and once as ending minute.

This can be reproduced with:

parsed  = OpeningHoursConverter::OpeningHoursParser.new('Mo-Su 10:00-18:00')
week = parsed.first.typical
week.get_as_minute_array.each do |day|
   puts day.count
end
#> 
1441
1441
1441
1441
1441
1441
1441

This is probably a bug. Especially since it is undefined what minute is added.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.