Permalink
Browse files

Conflicts working with single recurrence events

  • Loading branch information...
1 parent 21e6990 commit ffb946aa12412d6cfc1ed969313aa111e1984645 @mrloop committed Mar 5, 2012
Showing with 53 additions and 13 deletions.
  1. +18 −5 lib/ice_cube/schedule.rb
  2. +35 −8 spec/examples/schedule_spec.rb
View
@@ -182,11 +182,13 @@ def occurs_on?(date)
# Determine if the schedule is occurring at a given time
def occurring_at?(time)
- time = time.to_time
+#time = time.to_time
if duration
return false if exception_time?(time)
- occurs_between?(time,time + duration)
- else
+#occurs_between?(time,time + duration)
+occurs_between?(time - duration + 1, time+1)
+
+else
occurs_at?(time)
end
end
@@ -220,10 +222,21 @@ def conflicts_with?(other_schedule, closing_time = nil)
end
# Due to durations, we need to walk up to the end time, and verify in the
# other direction
- if last_time
+
+ if other_schedule.terminating?
+ last_time = nil
+ other_schedule.each_occurrence do |time|
+ if closing_time && time > closing_time
+ last_time = closing_time
+ break
+ end
+ last_time = time
+ puts "a time #{time}"
+ return true if terminating_schedule.occurring_at?(time)
+ end
+ elsif last_time
other_schedule.each_occurrence do |time|
break if time > last_time
- puts "another time #{time}"
return true if terminating_schedule.occurring_at?(time)
end
end
@@ -99,22 +99,49 @@
should be_false
end
- it 'should return true if conflict is present and no rules set' do
+ it 'should return false if conflict is not present based on duration' do
start_time = Time.now
- schedule1 = IceCube::Schedule.new(start_time)
- schedule2 = IceCube::Schedule.new(start_time)
- conflict = schedule1.conflicts_with?(schedule2, start_time + IceCube::ONE_DAY)
- conflict.should be_true
+ schedule1 = IceCube::Schedule.new(start_time, :duration => IceCube::ONE_HOUR)
+ schedule1.rrule IceCube::Rule.weekly.day(:monday)
+ schedule2 = IceCube::Schedule.new(start_time, :duration => IceCube::ONE_HOUR)
+ schedule2.rrule IceCube::Rule.weekly.day(:tuesday)
+ conflict = schedule1.conflicts_with?(schedule2, start_time + IceCube::ONE_WEEK)
+ conflict.should be_false
end
- it 'should return false if conflict is not present and no rules set' do
+ it 'should return false if conflict is not present on same day based on duration' do
start_time = Time.now
- schedule1 = IceCube::Schedule.new(start_time)
- schedule2 = IceCube::Schedule.new(start_time+IceCube::ONE_DAY)
+ schedule1 = IceCube::Schedule.new(start_time, :duration => IceCube::ONE_HOUR)
+ schedule1.rrule IceCube::Rule.daily
+ schedule2 = IceCube::Schedule.new(start_time + 1.hour, :duration => IceCube::ONE_HOUR)
+ schedule2.rrule IceCube::Rule.daily
conflict = schedule1.conflicts_with?(schedule2, start_time + IceCube::ONE_WEEK)
conflict.should be_false
end
+ it 'should return true if conflict is present on same day based on duration' do
+ start_time = Time.now
+ schedule1 = IceCube::Schedule.new(start_time, :duration => IceCube::ONE_HOUR)
+ schedule1.rrule IceCube::Rule.daily
+ schedule2 = IceCube::Schedule.new(start_time + 10.minutes, :duration => IceCube::ONE_HOUR)
+ schedule2.rrule IceCube::Rule.daily
+ conflict = schedule1.conflicts_with?(schedule2, start_time + IceCube::ONE_WEEK)
+ conflict.should be_true
+ end
+
+ it 'should return true if conflict is present and no recurrence' do
+ start_time = Time.now
+ schedule1 = IceCube::Schedule.new(start_time, :duration => IceCube::ONE_HOUR)
+ schedule1.add_recurrence_time(start_time)
+ schedule2 = IceCube::Schedule.new(start_time + 10.minutes, :duration => IceCube::ONE_HOUR)
+ schedule2.add_recurrence_time(start_time + 10.minutes)
+ conflict = schedule1.conflicts_with?(schedule2)
+ conflict.should be_true
+ conflict = schedule2.conflicts_with?(schedule1)
+ conflict.should be_true
+ end
+
+
end
describe :each do

0 comments on commit ffb946a

Please sign in to comment.