Skip to content

Commit 656c0c4

Browse files
authored
[Bugfix] Weekly interval rules are sometimes calculated incorrectly (#487)
* fix offset bug when base_interval_validation.type is not hourly * bug fix for interval validation * Fix linting * update changelog for #487 bugfix
1 parent 2fa867f commit 656c0c4

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
### Added
99
- Indonesian translations. ([#505](https://github.com/seejohnrun/ice_cube/pull/505)) by [@achmiral](https://github.com/achmiral)
1010

11+
### Fixed
12+
- 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)
13+
1114
## [0.16.4] - 2021-10-21
1215
### Added
1316
- Italian translations
@@ -84,7 +87,7 @@ NOTE: the commit for the _v0.13.0_ release tag incorrectly says _Release 0.13.1_
8487
- Fix whole-day skip with date inputs
8588
- Missed times selected from gap week with weekly interval > 1 ([#241](https://github.com/seejohnrun/ice_cube/pull/241))
8689
- Fix `occurs_on?` miss near midnight for DST ([#245](https://github.com/seejohnrun/ice_cube/pull/245))
87-
90+
8891
## [0.12.1] - 2014-07-04
8992
### Added
9093
- Support for deserialization of times via Time.parse

lib/ice_cube/validated_rule.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ def other_interval_validations
4646
# to the given start time
4747
def next_time(time, start_time, closing_time)
4848
@time = time
49-
unless @start_time
50-
@start_time = realign(time, start_time)
51-
@time = @start_time if @time < @start_time
52-
end
49+
@start_time ||= realign(time, start_time)
50+
@time = @start_time if @time < @start_time
5351

5452
return nil unless find_acceptable_time_before(closing_time)
5553

spec/examples/weekly_rule_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,19 @@ module IceCube
288288
expect(schedule.next_occurrence(sample[2] - 1)).to eq(sample[2])
289289
end
290290

291+
it "should respect weekly intervals within narrow occurrence ranges" do
292+
start_time = Time.utc(2020, 10, 27, 7, 0, 0)
293+
schedule = Schedule.new(start_time, end_time: start_time + ONE_HOUR)
294+
occurrence_start = Time.utc(2020, 11, 5, 0, 0, 0)
295+
occurrence_end = Time.utc(2020, 11, 5, 23, 59, 59)
296+
297+
schedule.add_recurrence_rule IceCube::Rule.weekly(2).day(:thursday).hour_of_day(13)
298+
schedule.add_recurrence_rule IceCube::Rule.weekly(1).day(:thursday).hour_of_day(12)
299+
expect(schedule.occurrences_between(occurrence_start, occurrence_end)).to eq([
300+
Time.utc(2020, 11, 5, 12, 0, 0)
301+
])
302+
end
303+
291304
it "should align next_occurrence with first valid weekday when schedule starts on a Wednesday" do
292305
t0 = Time.utc(2017, 6, 7)
293306
schedule = IceCube::Schedule.new(t0)

0 commit comments

Comments
 (0)