Skip to content

Commit 5d9b32c

Browse files
committed
Check edge cases for biweekly schedule
1 parent 8b72469 commit 5d9b32c

File tree

2 files changed

+17
-37
lines changed

2 files changed

+17
-37
lines changed

spec/examples/ice_cube_spec.rb

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,24 @@
308308
dates.should == [start_time + IceCube::ONE_DAY * 2, start_time + IceCube::ONE_DAY * 3, start_time + IceCube::ONE_DAY * 4]
309309
end
310310

311-
it 'should use start date on a bi-weekly recurrence pattern to find the occurrences_between when interval > 1' do
312-
start_time = Time.local(2011, 3, 20)
313-
314-
schedule = IceCube::Schedule.new(start_time)
315-
schedule.add_recurrence_rule IceCube::Rule.weekly(2).day(:sunday)
311+
describe "using occurs_between with a biweekly schedule" do
312+
[[0, 1, 2], [0, 6, 1], [5, 1, 6], [6, 5, 7]].each do |wday, offset, lead|
313+
start_week = Time.utc(2014, 1, 5)
314+
expected_week = start_week + 2.weeks
315+
offset_wday = (wday + offset) % 7
316+
317+
context "starting on weekday #{wday} selecting weekday #{offset} with a #{lead} day advance window" do
318+
let(:biweekly) { Rule.weekly(2).day(0, 1, 2, 3, 4, 5, 6) }
319+
let(:schedule) { Schedule.new(start_week + wday.days) { |s| s.rrule biweekly } }
320+
let(:expected_date) { expected_week + offset_wday.days }
321+
let(:range) { [expected_date - lead.days, expected_date] }
322+
323+
it "should include weekday #{offset_wday} of the expected week" do
324+
expect(schedule.occurrences_between(range.first, range.last)).to include expected_date
325+
end
326+
end
316327

317-
occurrences = schedule.occurrences_between(Time.local(2012, 7, 7), Time.local(2012, 7, 9))
318-
occurrences.should == [Time.local(2012, 7, 8)]
328+
end
319329
end
320330

321331
it 'should be able to tell us when there is at least one occurrence between two dates' do

spec/examples/regression_spec.rb

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -229,35 +229,5 @@ module IceCube
229229
end
230230
end
231231

232-
describe 'weekly schedule using occurs_between' do
233-
let(:schedule) {Schedule.new('2014-01-08'.to_date)}
234-
let(:expected_occurrence) {'2014-07-24'.to_date.to_time}
235-
before :each do
236-
schedule.add_recurrence_rule rule
237-
end
238-
239-
context "with interval" do
240-
let(:rule) {Rule.weekly(2).day([4,5,6])}
241-
it "should include the expected date [#241]" do
242-
expect(schedule.occurrences_between(expected_occurrence - 7.days, expected_occurrence + 7.days)).to include(expected_occurrence)
243-
expect(schedule.occurrences_between(expected_occurrence - 1.day, expected_occurrence + 1.day)).to include(expected_occurrence)
244-
expect(schedule.occurrences_between(expected_occurrence - 6.days, expected_occurrence + 6.days)).to include(expected_occurrence)
245-
expect(schedule.occurrences_between(expected_occurrence - 5.days, expected_occurrence + 5.days)).to include(expected_occurrence)
246-
end
247-
end
248-
249-
context "without interval" do
250-
let(:rule) {Rule.weekly(1).day([4,5,6])}
251-
it "should include the expected date" do
252-
expect(schedule.occurs_on?(expected_occurrence)).to be_true
253-
expect(schedule.occurrences_between(expected_occurrence - 7.days, expected_occurrence + 7.days)).to include(expected_occurrence)
254-
expect(schedule.occurrences_between(expected_occurrence - 1.day, expected_occurrence + 1.day)).to include(expected_occurrence)
255-
expect(schedule.occurrences_between(expected_occurrence - 6.days, expected_occurrence + 6.days)).to include(expected_occurrence)
256-
expect(schedule.occurrences_between(expected_occurrence - 5.days, expected_occurrence + 5.days)).to include(expected_occurrence)
257-
end
258-
end
259-
260-
end
261-
262232
end
263233
end

0 commit comments

Comments
 (0)