From b299a4461e3e5ed751dc6e3bbd4bd5057f32fca7 Mon Sep 17 00:00:00 2001 From: Jake Brady Date: Tue, 7 Aug 2018 13:39:21 -0700 Subject: [PATCH 1/2] fix offset bug when base_interval_validation.type is not hourly --- lib/ice_cube/validations/hour_of_day.rb | 2 +- spec/examples/weekly_rule_spec.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/ice_cube/validations/hour_of_day.rb b/lib/ice_cube/validations/hour_of_day.rb index 291708e6..819c394d 100644 --- a/lib/ice_cube/validations/hour_of_day.rb +++ b/lib/ice_cube/validations/hour_of_day.rb @@ -23,7 +23,7 @@ def realign(opening_time, start_time) first_hour = Array(validations[:hour_of_day]).min_by(&:value) time = TimeUtil::TimeWrapper.new(start_time, false) - if freq > 1 + if freq > 1 && base_interval_validation.type == :hour offset = first_hour.validate(opening_time, start_time) time.add(:hour, offset - freq) else diff --git a/spec/examples/weekly_rule_spec.rb b/spec/examples/weekly_rule_spec.rb index 682a85e4..e48f23cb 100644 --- a/spec/examples/weekly_rule_spec.rb +++ b/spec/examples/weekly_rule_spec.rb @@ -338,6 +338,19 @@ module IceCube end end end + + context 'when base interval validation type is not hourly' do + let(:start_time) { Time.utc(2018, 8, 7, 7, 0, 0) } + let(:end_time) { Time.utc(2018, 8, 7, 15, 0, 0) } + let(:biweekly) { IceCube::Rule.weekly(2).day(:saturday).hour_of_day(10) } + let(:schedule) { IceCube::Schedule.new(start_time, end_time: end_time) { |s| s.rrule biweekly } } + let(:range) { [Time.utc(2018, 8, 11, 7, 0, 0), Time.utc(2018, 8, 12, 6, 59, 59)] } + let(:expected_date) { Time.utc(2018, 8, 11, 10, 0, 0) } + + it 'does not offset hour when base interval validation type is not hourly' do + expect(schedule.occurrences_between(range.first, range.last, spans: true)).to include expected_date + end + end end describe "using occurs_between with a weekly schedule" do From 6ef6c13b4992d447378a47a1f2860b316bd605f7 Mon Sep 17 00:00:00 2001 From: Jake Brady Date: Wed, 31 Oct 2018 16:04:57 -0700 Subject: [PATCH 2/2] update spec language, align hours to simplify scenario --- spec/examples/weekly_rule_spec.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/spec/examples/weekly_rule_spec.rb b/spec/examples/weekly_rule_spec.rb index e48f23cb..4c805642 100644 --- a/spec/examples/weekly_rule_spec.rb +++ b/spec/examples/weekly_rule_spec.rb @@ -339,15 +339,22 @@ module IceCube end end - context 'when base interval validation type is not hourly' do - let(:start_time) { Time.utc(2018, 8, 7, 7, 0, 0) } + # August 2018 + # Su Mo Tu We Th Fr Sa + # 1 2 3 4 + # 5 6 7 8 9 10 11 + # 12 13 14 15 16 17 18 + # 19 20 21 22 23 24 25 + # 26 27 28 29 30 31 + context 'when day of start_time does not align with specified day rule' do + let(:start_time) { Time.utc(2018, 8, 7, 10, 0, 0) } let(:end_time) { Time.utc(2018, 8, 7, 15, 0, 0) } let(:biweekly) { IceCube::Rule.weekly(2).day(:saturday).hour_of_day(10) } let(:schedule) { IceCube::Schedule.new(start_time, end_time: end_time) { |s| s.rrule biweekly } } let(:range) { [Time.utc(2018, 8, 11, 7, 0, 0), Time.utc(2018, 8, 12, 6, 59, 59)] } let(:expected_date) { Time.utc(2018, 8, 11, 10, 0, 0) } - it 'does not offset hour when base interval validation type is not hourly' do + it 'should align to the correct day with the spans option' do expect(schedule.occurrences_between(range.first, range.last, spans: true)).to include expected_date end end