Skip to content

Inconsistent occurrences_between behaviour on weekly intervals #241

@hughkelsey

Description

@hughkelsey

Lots of head scratching going on here...

I have a rule for 3 days every other week and occurrences_between gives me the correct result when I look for occurrences +/- 7 days from an expected date and +/- 1 day but I get an incorrect result when looking +/- 5 or 6 days.

require 'ice_cube'
IceCube::VERSION # "0.12.0" 

start_date = Date.parse('2014-01-08')
schedule = IceCube::Schedule.new(start_date)
schedule.add_recurrence_rule IceCube::Rule.weekly(2).day([4,5,6])

expected = Date.parse('2014-07-24') # Thursday

schedule.occurs_on?(expected) # true

schedule.occurrences_between(expected - 7, expected + 7).include?(expected.to_time) # true
schedule.occurrences_between(expected - 1, expected + 1).include?(expected.to_time) # true
schedule.occurrences_between(expected - 6, expected + 6).include?(expected.to_time) # false
schedule.occurrences_between(expected - 6, expected + 1).include?(expected.to_time) # false
schedule.occurrences_between(expected - 5, expected + 6).include?(expected.to_time) # false
schedule.occurrences_between(expected - 1, expected + 6).include?(expected.to_time) # true
schedule.occurrences_between(expected - 4, expected + 6).include?(expected.to_time) # true

I've forked ice_cube and added a failing spec (pr to follow).

describe 'weekly schedule with interval' do
  let(:schedule) {Schedule.new('2014-01-08'.to_date)}
  let(:expected_occurrence) {'2014-07-24'.to_date.to_time}

  before :each do
    schedule.add_recurrence_rule Rule.weekly(2).day([4,5,6])
  end
  it "should include the expected date" do
    expect(schedule.occurs_on?(expected_occurrence)).to be_true
    expect(schedule.occurrences_between(expected_occurrence - 7.days, expected_occurrence + 7.days)).to include(expected_occurrence)
    expect(schedule.occurrences_between(expected_occurrence - 1.day, expected_occurrence + 1.day)).to include(expected_occurrence)
    expect(schedule.occurrences_between(expected_occurrence - 6.days, expected_occurrence + 6.days)).to include(expected_occurrence) # fails here
    expect(schedule.occurrences_between(expected_occurrence - 5.days, expected_occurrence + 5.days)).to include(expected_occurrence)
  end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions