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..4c805642 100644 --- a/spec/examples/weekly_rule_spec.rb +++ b/spec/examples/weekly_rule_spec.rb @@ -338,6 +338,26 @@ module IceCube end end end + + # 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 '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 end describe "using occurs_between with a weekly schedule" do