Skip to content

Commit 2cdfdba

Browse files
authored
Correctly export exrules (#519)
* Remove deprecation of exrules * Always include exrules in hash of schedule, regardless of gem version * Update changelog
1 parent ae5e7b2 commit 2cdfdba

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
### Fixed
1212
- 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)
1313
- 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)
14+
- 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)
1415

1516
## [0.16.4] - 2021-10-21
1617
### Added

lib/ice_cube/parsers/hash_parser.rb

-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ def apply_rrules(schedule, data)
6060

6161
def apply_exrules(schedule, data)
6262
return unless data[:exrules]
63-
warn "IceCube: :exrules is deprecated, and will be removed in a future release. at: #{caller(1..1).first}"
6463
data[:exrules].each do |h|
6564
rrule = h.is_a?(IceCube::Rule) ? h : IceCube::Rule.from_hash(h)
6665

lib/ice_cube/schedule.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,7 @@ def to_hash
358358
data[:start_date] = data[:start_time] if IceCube.compatibility <= 11
359359
data[:end_time] = TimeUtil.serialize_time(end_time) if end_time
360360
data[:rrules] = recurrence_rules.map(&:to_hash)
361-
if IceCube.compatibility <= 11 && exception_rules.any?
362-
data[:exrules] = exception_rules.map(&:to_hash)
363-
end
361+
data[:exrules] = exception_rules.map(&:to_hash) if exception_rules.any?
364362
data[:rtimes] = recurrence_times.map do |rt|
365363
TimeUtil.serialize_time(rt)
366364
end

spec/examples/to_yaml_spec.rb

+12
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@ module IceCube
132132
expect(schedule.first(10).map { |r| r.to_s }).to eq(schedule2.first(10).map { |r| r.to_s })
133133
end
134134

135+
it "should be able to make a round-trip to YAML whilst preserving exception rules" do
136+
original_schedule = Schedule.new(Time.now)
137+
original_schedule.add_recurrence_rule Rule.daily.day(:monday, :wednesday)
138+
original_schedule.add_exception_rule Rule.daily.day(:wednesday)
139+
140+
yaml_string = original_schedule.to_yaml
141+
returned_schedule = Schedule.from_yaml(yaml_string)
142+
143+
# compare without usecs
144+
expect(returned_schedule.first(10).map { |r| r.to_s }).to eq(original_schedule.first(10).map { |r| r.to_s })
145+
end
146+
135147
it "should have a to_yaml representation of a rule that does not contain ruby objects" do
136148
rule = Rule.daily.day_of_week(monday: [1, -1]).month_of_year(:april)
137149
expect(rule.to_yaml.include?("object")).to be_falsey

0 commit comments

Comments
 (0)