Skip to content

Commit

Permalink
Merge pull request #92 from cawinkelmann/master
Browse files Browse the repository at this point in the history
Schedule find_occurrence when interval is greater than 1 won't use the start date causing invalid results
  • Loading branch information
seejohnrun committed Oct 11, 2012
2 parents f393819 + 62847b0 commit b592cb6
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/ice_cube/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def on?(time, schedule)

# Whether this rule requires a full run
def full_required?
!@count.nil?
!@count.nil? || (! @interval.nil? && @interval > 1)
end

# Convenience methods for creating Rules
Expand Down
1 change: 1 addition & 0 deletions lib/ice_cube/validations/daily_interval.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Validations::DailyInterval

# Add a new interval validation
def interval(interval)
@interval = interval
validations_for(:interval) << Validation.new(interval)
clobber_base_validations(:wday, :day)
self
Expand Down
1 change: 1 addition & 0 deletions lib/ice_cube/validations/monthly_interval.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module IceCube
module Validations::MonthlyInterval

def interval(interval = 1)
@interval = interval
validations_for(:interval) << Validation.new(interval)
clobber_base_validations(:month)
self
Expand Down
1 change: 1 addition & 0 deletions lib/ice_cube/validations/weekly_interval.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module IceCube
module Validations::WeeklyInterval

def interval(interval, week_start = :sunday)
@interval = interval
validations_for(:interval) << Validation.new(interval, week_start)
clobber_base_validations(:day)
self
Expand Down
1 change: 1 addition & 0 deletions lib/ice_cube/validations/yearly_interval.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module IceCube
module Validations::YearlyInterval

def interval(interval = 1)
@interval = interval
validations_for(:interval) << Validation.new(interval)
clobber_base_validations(:year)
end
Expand Down
12 changes: 12 additions & 0 deletions spec/examples/daily_rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,16 @@
]
end

context "full_required?" do
it "should return true when interval is > 1" do
rule = IceCube::Rule.daily(2)
rule.full_required?.should be_true
end

it "should return false when interval is <= 1" do
rule = IceCube::Rule.daily
rule.full_required?.should be_false
end
end

end
11 changes: 11 additions & 0 deletions spec/examples/ice_cube_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,16 @@
dates.should == [start_time + IceCube::ONE_DAY * 2, start_time + IceCube::ONE_DAY * 3, start_time + IceCube::ONE_DAY * 4]
end

it 'should use start date on a bi-weekly recurrence pattern to find the occurrences_between when interval > 1' do
start_date = Time.local(2011, 3, 20)

schedule = IceCube::Schedule.new(start_date)
schedule.add_recurrence_rule IceCube::Rule.weekly(2).day(:sunday)

occurrences = schedule.occurrences_between(Time.local(2012, 7, 7), Time.local(2012, 7, 9))
occurrences.should == [Time.local(2012, 7, 8)]
end

it 'should be able to tell us when there is at least one occurrence between two dates' do
start_date = WEDNESDAY
schedule = IceCube::Schedule.new(start_date)
Expand Down Expand Up @@ -780,5 +790,6 @@
rule.occurrence_count.should == 5
end


end

12 changes: 12 additions & 0 deletions spec/examples/monthly_rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,17 @@
#check assumption (12 months - 2 dates each)
schedule.occurrences(end_date).size.should == 24
end

context "full_required?" do
it "should return true when interval is > 1" do
rule = IceCube::Rule.monthly(2)
rule.full_required?.should be_true
end

it "should return false when interval is <= 1" do
rule = IceCube::Rule.monthly
rule.full_required?.should be_false
end
end

end
12 changes: 12 additions & 0 deletions spec/examples/weekly_rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,16 @@
schedule.first(3).should == [Time.local(2012,2,7), Time.local(2012,2,19), Time.local(2012,2,21)]
end

context "full_required?" do
it "should return true when interval is > 1" do
rule = IceCube::Rule.weekly(2).day(:sunday)
rule.full_required?.should be_true
end

it "should return false when interval is <= 1" do
rule = IceCube::Rule.weekly.day(:sunday)
rule.full_required?.should be_false
end
end

end
13 changes: 12 additions & 1 deletion spec/examples/yearly_rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,16 @@
#check assumption
schedule.occurrences(Time.utc(2010, 12, 31)).size.should == 2
end


context "full_required?" do
it "should return true when interval is > 1" do
rule = IceCube::Rule.yearly(2)
rule.full_required?.should be_true
end

it "should return false when interval is <= 1" do
rule = IceCube::Rule.yearly
rule.full_required?.should be_false
end
end
end

0 comments on commit b592cb6

Please sign in to comment.