diff --git a/lib/ice_cube/schedule.rb b/lib/ice_cube/schedule.rb index b90ca40c..448008c8 100644 --- a/lib/ice_cube/schedule.rb +++ b/lib/ice_cube/schedule.rb @@ -174,7 +174,11 @@ def next_occurrences(num, from = nil) # The next occurrence after now (overridable) def next_occurrence(from = nil) from ||= TimeUtil.now(@start_time) - enumerate_occurrences(from + 1, nil).next() + begin + enumerate_occurrences(from + 1, nil).next() + rescue StopIteration + nil + end end # The previous occurrence from a given time @@ -210,13 +214,12 @@ def occurrences_between(begin_time, closing_time) # Return a boolean indicating if an occurrence falls between two times def occurs_between?(begin_time, closing_time) - begin + begin enumerate_occurrences(begin_time, closing_time).next() true rescue StopIteration false end - end # Return a boolean indicating if an occurrence is occurring between two diff --git a/spec/examples/schedule_spec.rb b/spec/examples/schedule_spec.rb index ae29141e..149a53e0 100644 --- a/spec/examples/schedule_spec.rb +++ b/spec/examples/schedule_spec.rb @@ -26,6 +26,15 @@ schedule.start_time.should == Time.local(dt.year, dt.month, dt.day, dt.hour, dt.min, dt.sec) end + describe :next_occurrence do + + it 'should not raise an exception when calling next occurrence with no remaining occurrences' do + schedule = IceCube::Schedule.new Time.now + lambda { schedule.next_occurrence }.should_not raise_error + end + + end + describe :duration do it 'should be based on end_time' do