Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where daily intervals > 1 start on the wrong date #515

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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 @@ -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
Expand Down
12 changes: 12 additions & 0 deletions spec/examples/daily_rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down