From aa29161d4a76fc09bb23297c1e5ac05aa8b83c00 Mon Sep 17 00:00:00 2001 From: Jon Pascoe Date: Tue, 8 Feb 2022 22:58:42 +0000 Subject: [PATCH 1/3] Remove deprecation of exrules --- lib/ice_cube/parsers/hash_parser.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/ice_cube/parsers/hash_parser.rb b/lib/ice_cube/parsers/hash_parser.rb index abe7f6a6..d0d6713b 100644 --- a/lib/ice_cube/parsers/hash_parser.rb +++ b/lib/ice_cube/parsers/hash_parser.rb @@ -60,7 +60,6 @@ def apply_rrules(schedule, data) def apply_exrules(schedule, data) return unless data[:exrules] - warn "IceCube: :exrules is deprecated, and will be removed in a future release. at: #{caller(1..1).first}" data[:exrules].each do |h| rrule = h.is_a?(IceCube::Rule) ? h : IceCube::Rule.from_hash(h) From c5239d2903b89069454c03a499fb8251a1fdc2de Mon Sep 17 00:00:00 2001 From: Jon Pascoe Date: Tue, 8 Feb 2022 22:59:49 +0000 Subject: [PATCH 2/3] Always include exrules in hash of schedule, regardless of gem version --- lib/ice_cube/schedule.rb | 4 +--- spec/examples/to_yaml_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/ice_cube/schedule.rb b/lib/ice_cube/schedule.rb index 5fbb9530..68f01cc9 100644 --- a/lib/ice_cube/schedule.rb +++ b/lib/ice_cube/schedule.rb @@ -358,9 +358,7 @@ def to_hash data[:start_date] = data[:start_time] if IceCube.compatibility <= 11 data[:end_time] = TimeUtil.serialize_time(end_time) if end_time data[:rrules] = recurrence_rules.map(&:to_hash) - if IceCube.compatibility <= 11 && exception_rules.any? - data[:exrules] = exception_rules.map(&:to_hash) - end + data[:exrules] = exception_rules.map(&:to_hash) if exception_rules.any? data[:rtimes] = recurrence_times.map do |rt| TimeUtil.serialize_time(rt) end diff --git a/spec/examples/to_yaml_spec.rb b/spec/examples/to_yaml_spec.rb index 7842621c..f8fcade9 100644 --- a/spec/examples/to_yaml_spec.rb +++ b/spec/examples/to_yaml_spec.rb @@ -132,6 +132,18 @@ module IceCube expect(schedule.first(10).map { |r| r.to_s }).to eq(schedule2.first(10).map { |r| r.to_s }) end + it "should be able to make a round-trip to YAML whilst preserving exception rules" do + original_schedule = Schedule.new(Time.now) + original_schedule.add_recurrence_rule Rule.daily.day(:monday, :wednesday) + original_schedule.add_exception_rule Rule.daily.day(:wednesday) + + yaml_string = original_schedule.to_yaml + returned_schedule = Schedule.from_yaml(yaml_string) + + # compare without usecs + expect(returned_schedule.first(10).map { |r| r.to_s }).to eq(original_schedule.first(10).map { |r| r.to_s }) + end + it "should have a to_yaml representation of a rule that does not contain ruby objects" do rule = Rule.daily.day_of_week(monday: [1, -1]).month_of_year(:april) expect(rule.to_yaml.include?("object")).to be_falsey From ce0b32fb8049486c62a3047febb45e6ee6d8d6cd Mon Sep 17 00:00:00 2001 From: Jon Pascoe Date: Tue, 8 Feb 2022 23:09:38 +0000 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b227ad7e..5b8c8aea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) +- 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) ## [0.16.4] - 2021-10-21 ### Added