diff --git a/.standard_todo.yml b/.standard_todo.yml deleted file mode 100644 index 0933abc0..00000000 --- a/.standard_todo.yml +++ /dev/null @@ -1,12 +0,0 @@ -# Auto generated files with errors to ignore. -# Remove from this list as you refactor files. ---- -ignore: -- lib/ice_cube/parsers/yaml_parser.rb: - - Security/YAMLLoad -- lib/ice_cube/rule.rb: - - Security/YAMLLoad -- spec/examples/serialization_spec.rb: - - Security/YAMLLoad -- spec/examples/to_yaml_spec.rb: - - Security/YAMLLoad diff --git a/CHANGELOG.md b/CHANGELOG.md index c0022b92..e59b38ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/ice_cube/validations/hour_of_day.rb b/lib/ice_cube/validations/hour_of_day.rb index e0a9c3be..c653cffd 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 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..434f12d8 100644 --- a/spec/examples/daily_rule_spec.rb +++ b/spec/examples/daily_rule_spec.rb @@ -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 diff --git a/spec/examples/weekly_rule_spec.rb b/spec/examples/weekly_rule_spec.rb index 3e8e5719..eda1d59a 100644 --- a/spec/examples/weekly_rule_spec.rb +++ b/spec/examples/weekly_rule_spec.rb @@ -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