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 daily schedule bug #523

Draft
wants to merge 7 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
12 changes: 0 additions & 12 deletions .standard_todo.yml

This file was deleted.

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- 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)
- Include `exrules` when exporting a schedule to YAML, JSON or a Hash. ([#519](https://github.com/ice-cube-ruby/ice_cube/pull/519)) by [@pacso](https://github.com/pacso)
- Revert [#452](https://github.com/ice-cube-ruby/ice_cube/pull/452) which resolves the issue it introduced, detailed in [#514](https://github.com/ice-cube-ruby/ice_cube/issues/514)

## [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
offset = first_hour.validate(opening_time, start_time)
time.add(:hour, offset - freq)
else
Expand Down
23 changes: 19 additions & 4 deletions spec/examples/daily_rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,25 @@ module IceCube
schedule.add_recurrence_rule Rule.daily(4).hour_of_day(5).minute_of_hour(45)
# check assumption 2 -- 1 (2) (3) (4) 5 (6)
times = schedule.occurrences(t0 + 5 * ONE_DAY)
expect(times).to eq([
t0 + 5 * ONE_HOUR + 45 * ONE_MINUTE,
t0 + 4 * ONE_DAY + 5 * ONE_HOUR + 45 * ONE_MINUTE
])
expect(times)
.to eq([
t0 + 5 * ONE_HOUR + 45 * ONE_MINUTE,
t0 + 4 * ONE_DAY + 5 * ONE_HOUR + 45 * ONE_MINUTE
])
end

it "selects the first possible starting occurrence before starting interval" do
schedule_start = Time.new(2021, 3, 28, 10, 0, 0, "+00:00")
end_time = Time.new(2021, 4, 7, 23, 59, 59, "+00:00")
rule = IceCube::Rule.daily(4).hour_of_day(9).minute_of_hour(0).second_of_minute(0)
schedule = IceCube::Schedule.new(schedule_start) { |s| s.add_recurrence_rule(rule) }

expect(schedule.occurrences(end_time))
.to eq([
Time.new(2021, 3, 29, 9, 0, 0, "+00:00"),
Time.new(2021, 4, 2, 9, 0, 0, "+00:00"),
Time.new(2021, 4, 6, 9, 0, 0, "+00:00")
])
end

describe "day validation" do
Expand Down
7 changes: 5 additions & 2 deletions spec/examples/weekly_rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,15 @@ module IceCube
# 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) }
let(:schedule) { IceCube::Schedule.new(start_time, end_time: end_time) { |s| s.rrule biweekly } }
let(:schedule) { IceCube::Schedule.new(start_time, duration: ONE_HOUR) { |s| s.add_recurrence_rule 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 "selects the correct first occurrence" do
expect(schedule.occurrences(Time.utc(2018, 8, 12))).to match_array [expected_date]
end

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