Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing biweekly realign when used with spans option. #377

Merged
merged 1 commit into from
Feb 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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