Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ice_cube/validations/hour_of_day.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions spec/examples/weekly_rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are both day and hour_of_day needed for this scenario? I'd like to keep this isolated to the single issue at hand if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed on wanting to simplify the scenario. I was unable to reproduce this bug without both validation requirements also being present.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it only affects weekly schedules, then I think it belongs here.

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
Expand Down