Skip to content

Commit

Permalink
Fixing biweekly realign when used with spans option
Browse files Browse the repository at this point in the history
The realign method should be working from the pure opening time without the duration shift used for the spans option.
  • Loading branch information
jopotts committed Feb 23, 2017
1 parent c9292c4 commit 8c846a8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ice_cube/schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def enumerate_occurrences(opening_time, closing_time = nil, options = {}, &block
spans = options[:spans] == true && duration != 0
Enumerator.new do |yielder|
reset
t1 = full_required? ? start_time : realign((spans ? opening_time - duration : opening_time))
t1 = full_required? ? start_time : realign(opening_time) - (spans ? duration : 0)
loop do
break unless (t0 = next_time(t1, closing_time))
break if closing_time && t0 > closing_time
Expand Down
10 changes: 10 additions & 0 deletions spec/examples/weekly_rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ module IceCube
])
end

it 'should find the next date on a biweekly sunday searching from a few days before the date' do
t0 = Time.utc(2017, 1, 15, 9, 0, 0)
t1 = Time.utc(2017, 1, 24)
t2 = t0 + (2 * ONE_WEEK)
schedule = Schedule.new(t0, :duration => IceCube::ONE_HOUR)
schedule.add_recurrence_rule Rule.weekly(2, :sunday).day(:sunday)
t3 = schedule.next_occurrence(t1, :spans => true)
expect(t3).to eq(t2)
end

it 'should validate week_start input' do
expect { Rule.weekly(2, :someday) }.to raise_error(ArgumentError)
end
Expand Down

0 comments on commit 8c846a8

Please sign in to comment.