Skip to content

Commit 8c846a8

Browse files
committed
Fixing biweekly realign when used with spans option
The realign method should be working from the pure opening time without the duration shift used for the spans option.
1 parent c9292c4 commit 8c846a8

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/ice_cube/schedule.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ def enumerate_occurrences(opening_time, closing_time = nil, options = {}, &block
413413
spans = options[:spans] == true && duration != 0
414414
Enumerator.new do |yielder|
415415
reset
416-
t1 = full_required? ? start_time : realign((spans ? opening_time - duration : opening_time))
416+
t1 = full_required? ? start_time : realign(opening_time) - (spans ? duration : 0)
417417
loop do
418418
break unless (t0 = next_time(t1, closing_time))
419419
break if closing_time && t0 > closing_time

spec/examples/weekly_rule_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@ module IceCube
165165
])
166166
end
167167

168+
it 'should find the next date on a biweekly sunday searching from a few days before the date' do
169+
t0 = Time.utc(2017, 1, 15, 9, 0, 0)
170+
t1 = Time.utc(2017, 1, 24)
171+
t2 = t0 + (2 * ONE_WEEK)
172+
schedule = Schedule.new(t0, :duration => IceCube::ONE_HOUR)
173+
schedule.add_recurrence_rule Rule.weekly(2, :sunday).day(:sunday)
174+
t3 = schedule.next_occurrence(t1, :spans => true)
175+
expect(t3).to eq(t2)
176+
end
177+
168178
it 'should validate week_start input' do
169179
expect { Rule.weekly(2, :someday) }.to raise_error(ArgumentError)
170180
end

0 commit comments

Comments
 (0)