diff --git a/CHANGELOG.md b/CHANGELOG.md index b227ad7e..8ac83ab6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fix for weekly interval results when requesting `occurrences_between` on a narrow range ([#487](https://github.com/seejohnrun/ice_cube/pull/487)) by [@jakebrady5](https://github.com/jakebrady5) - When using a rule with hour_of_day validations, and asking for occurrences on the day that DST skips forward, valid occurrences would be missed. ([#464](https://github.com/seejohnrun/ice_cube/pull/464)) by [@jakebrady5](https://github.com/jakebrady5) +- Fix for daily rules with intervals > 1 selecting the wrong start date for the first occurrence ([#515](https://github.com/seejohnrun/ice_cube/pull/515)) by [@pacso](https://github.com/pacso) ## [0.16.4] - 2021-10-21 ### Added diff --git a/lib/ice_cube/validations/hour_of_day.rb b/lib/ice_cube/validations/hour_of_day.rb index e0a9c3be..4f19d254 100644 --- a/lib/ice_cube/validations/hour_of_day.rb +++ b/lib/ice_cube/validations/hour_of_day.rb @@ -21,7 +21,7 @@ def realign(opening_time, start_time) first_hour = Array(validations[:hour_of_day]).min_by(&:value) time = TimeUtil::TimeWrapper.new(start_time, true) - if freq > 1 && base_interval_validation.type == :hour + 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/daily_rule_spec.rb b/spec/examples/daily_rule_spec.rb index 53887774..86c77b94 100644 --- a/spec/examples/daily_rule_spec.rb +++ b/spec/examples/daily_rule_spec.rb @@ -112,6 +112,18 @@ module IceCube ]) end + it "should set the first occurrance to the first valid time after schedule start" do + schedule = Schedule.new(Time.local(2013, 3, 8, 10, 0, 0)) + schedule.add_recurrence_rule Rule.daily(1).hour_of_day(9) + expect(schedule.first).to eq(Time.local(2013, 3, 9, 9, 0, 0)) + end + + it "should set the first occurrance to the first valid time after schedule start with interval > 1" do + schedule = Schedule.new(Time.local(2013, 3, 8, 10, 0, 0)) + schedule.add_recurrence_rule Rule.daily(4).hour_of_day(9) + expect(schedule.first).to eq(Time.local(2013, 3, 9, 9, 0, 0)) + end + describe "day validation" do it "allows multiples of 7" do expect { IceCube::Rule.daily(21).day(2, 4) }.to_not raise_error