Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Single recurrence and recurrences with duration conflict detection #71

Merged
merged 8 commits into from

3 participants

@mrloop

conflicts_with? now working with single recurrences with durations. Please see extras tests for examples.

@myth17

This seems to be quite useful, any plans of including this pull request?

@seejohnrun seejohnrun merged commit 97768a0 into seejohnrun:master
@seejohnrun
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 96 additions and 1 deletion.
  1. +3 −1 lib/ice_cube/schedule.rb
  2. +93 −0 spec/examples/schedule_spec.rb
View
4 lib/ice_cube/schedule.rb
@@ -10,7 +10,7 @@ class Schedule
attr_accessor :start_time
deprecated_alias :start_date, :start_time
deprecated_alias :start_date=, :start_time=
-
+
# Get the duration
attr_accessor :duration
@@ -179,6 +179,7 @@ def occurs_on?(date)
# Determine if the schedule is occurring at a given time
def occurring_at?(time)
+ time=time.to_time
if duration
return false if exception_time?(time)
occurs_between?(time - duration + 1, time)
@@ -215,6 +216,7 @@ def conflicts_with?(other_schedule, closing_time = nil)
# Due to durations, we need to walk up to the end time, and verify in the
# other direction
if last_time
+ last_time = terminating_schedule.duration ? last_time + terminating_schedule.duration : last_time
other_schedule.each_occurrence do |time|
break if time > last_time
return true if terminating_schedule.occurring_at?(time)
View
93 spec/examples/schedule_spec.rb
@@ -99,6 +99,99 @@
should be_false
end
+ it 'should return false if conflict is not present based on duration' do
+ start_time = Time.now
+ 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 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 + 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
+
+ it 'should return false if conflict is not 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 + IceCube::ONE_HOUR, :duration => IceCube::ONE_HOUR)
+ schedule2.add_recurrence_time(start_time + IceCube::ONE_HOUR)
+ conflict = schedule1.conflicts_with?(schedule2)
+ conflict.should be_false
+ conflict = schedule2.conflicts_with?(schedule1)
+ conflict.should be_false
+ end
+
+ it 'should return false if conflict is not present and single 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 + IceCube::ONE_HOUR, :duration => IceCube::ONE_HOUR)
+ schedule2.rrule IceCube::Rule.daily
+ conflict = schedule1.conflicts_with?(schedule2)
+ conflict.should be_false
+ conflict = schedule2.conflicts_with?(schedule1)
+ conflict.should be_false
+ end
+
+ it 'should return true if conflict is present and single 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.rrule IceCube::Rule.daily
+ conflict = schedule1.conflicts_with?(schedule2)
+ conflict.should be_true
+ conflict = schedule2.conflicts_with?(schedule1)
+ conflict.should be_true
+ end
+
+ it 'should return false if conflict is not present and single recurrence and time originally specified as DateTime' do
+ date = DateTime.new(2020,9,21,11,30,0)
+ start_time = date.to_time
+ schedule1 = IceCube::Schedule.new(start_time, :duration => IceCube::ONE_HOUR)
+ schedule1.add_recurrence_time(start_time)
+ schedule2 = IceCube::Schedule.new(start_time + IceCube::ONE_HOUR, :duration => IceCube::ONE_HOUR)
+ schedule2.add_recurrence_time(start_time + IceCube::ONE_HOUR)
+ conflict = schedule1.conflicts_with?(schedule2)
+ conflict.should be_false
+ conflict = schedule2.conflicts_with?(schedule1)
+ conflict.should be_false
+ end
+
+
+
end
describe :each do
Something went wrong with that request. Please try again.