Skip to content

Commit

Permalink
Fix a bug in exclude dates for occurs_on?
Browse files Browse the repository at this point in the history
  • Loading branch information
John Crepezzi committed Aug 27, 2010
1 parent 5f97398 commit 0ae99c8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/ice_cube/rule_occurrence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def succ
begin
return nil if @end_time && date > @end_time
return nil if @rule.until_date && date > @rule.until_date # until check
next unless @rule.in_interval?(date, @start_date)
return nil if yield(date)
next unless @rule.in_interval?(date, @start_date)
return RuleOccurrence.new(@rule, @start_date, @end_time, date, @index + 1)
end while date = @rule.next_suggestion(date)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/ice_cube/schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ def occurrences_between(begin_time, end_time)
# adjust to the propert end date
end_time = @end_time if @end_time && @end_time < end_time
# collect the occurrences
include_dates = SortedSet.new(@rdates)
include_dates, exclude_dates = SortedSet.new(@rdates), Set.new(@exdates)
@rrule_occurrence_heads.each do |rrule_occurrence_head|
include_dates.merge(rrule_occurrence_head.between(begin_time, end_time))
end
@exrule_occurrence_heads.each do |exrule_occurrence_head|
exclude_dates.merge(exrule_occurrence_head.between(begin_time, end_time))
end
# reject all of the ones outside of the range
include_dates.reject! { |date| (@exdates && @exdates.include?(date)) || date < begin_time || date > end_time }
include_dates.reject! { |date| exclude_dates.include?(date) || date < begin_time || date > end_time }
include_dates.to_a
end

Expand Down
10 changes: 9 additions & 1 deletion spec/examples/ice_cube_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,14 @@
schedule.exdate Time.local(2010, 8, 14)
schedule.exdates.should == [Time.local(2010, 8, 13), Time.local(2010, 8, 14)]
end


it 'should be able to have a rule and an exrule' do
schedule = IceCube::Schedule.new(Time.local(2010, 8, 27, 10))
schedule.rrule IceCube::Rule.daily
schedule.exrule IceCube::Rule.daily.day(:friday)
schedule.occurs_on?(Date.today).should be(false)
schedule.occurs_on?(Date.today + 1).should be(true)
end

end

2 changes: 2 additions & 0 deletions spec/examples/sample_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require File.dirname(__FILE__) + '/spec_helper'

#require 'active_support'

describe IceCube::Schedule, 'occurs_on?' do

end

0 comments on commit 0ae99c8

Please sign in to comment.