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

Correctly export exrules #519

Merged
merged 3 commits into from
Feb 21, 2022
Merged
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
@@ -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
1 change: 0 additions & 1 deletion lib/ice_cube/parsers/hash_parser.rb
Original file line number Diff line number Diff line change
@@ -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)

4 changes: 1 addition & 3 deletions lib/ice_cube/schedule.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions spec/examples/to_yaml_spec.rb
Original file line number Diff line number Diff line change
@@ -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