diff --git a/CHANGELOG.md b/CHANGELOG.md index b4ac47fd..b7d911a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Indonesian translations. ([#505](https://github.com/seejohnrun/ice_cube/pull/505)) by [@achmiral](https://github.com/achmiral) +### 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) + ## [0.16.4] - 2021-10-21 ### Added - Italian translations @@ -84,7 +87,7 @@ NOTE: the commit for the _v0.13.0_ release tag incorrectly says _Release 0.13.1_ - Fix whole-day skip with date inputs - Missed times selected from gap week with weekly interval > 1 ([#241](https://github.com/seejohnrun/ice_cube/pull/241)) - Fix `occurs_on?` miss near midnight for DST ([#245](https://github.com/seejohnrun/ice_cube/pull/245)) - + ## [0.12.1] - 2014-07-04 ### Added - Support for deserialization of times via Time.parse diff --git a/lib/ice_cube/validated_rule.rb b/lib/ice_cube/validated_rule.rb index 84b9ab56..068356ea 100644 --- a/lib/ice_cube/validated_rule.rb +++ b/lib/ice_cube/validated_rule.rb @@ -46,10 +46,8 @@ def other_interval_validations # to the given start time def next_time(time, start_time, closing_time) @time = time - unless @start_time - @start_time = realign(time, start_time) - @time = @start_time if @time < @start_time - end + @start_time ||= realign(time, start_time) + @time = @start_time if @time < @start_time return nil unless find_acceptable_time_before(closing_time) diff --git a/spec/examples/weekly_rule_spec.rb b/spec/examples/weekly_rule_spec.rb index 9a924d50..3e8e5719 100644 --- a/spec/examples/weekly_rule_spec.rb +++ b/spec/examples/weekly_rule_spec.rb @@ -288,6 +288,19 @@ module IceCube expect(schedule.next_occurrence(sample[2] - 1)).to eq(sample[2]) end + it "should respect weekly intervals within narrow occurrence ranges" do + start_time = Time.utc(2020, 10, 27, 7, 0, 0) + schedule = Schedule.new(start_time, end_time: start_time + ONE_HOUR) + occurrence_start = Time.utc(2020, 11, 5, 0, 0, 0) + occurrence_end = Time.utc(2020, 11, 5, 23, 59, 59) + + schedule.add_recurrence_rule IceCube::Rule.weekly(2).day(:thursday).hour_of_day(13) + schedule.add_recurrence_rule IceCube::Rule.weekly(1).day(:thursday).hour_of_day(12) + expect(schedule.occurrences_between(occurrence_start, occurrence_end)).to eq([ + Time.utc(2020, 11, 5, 12, 0, 0) + ]) + end + it "should align next_occurrence with first valid weekday when schedule starts on a Wednesday" do t0 = Time.utc(2017, 6, 7) schedule = IceCube::Schedule.new(t0)