ice-cube-ruby / ice_cube

Ruby Date Recurrence Library - Allows easy creation of recurrence rules and fast querying
MIT License
2.41k stars 358 forks source link

Exception rules no longer serializing? #323

Closed richardvenneman closed 8 years ago

richardvenneman commented 8 years ago

First of all thanks for the great gem :raised_hands: We've created hundreds of schedules over the past year with great success. However we seem to be running into some issues lately :)

Most of our schedules look something like this:

schedule = IceCube::Schedule.new(start = Time.utc(2015, 1, 1))
schedule.add_recurrence_rule IceCube::Rule.daily.day(:wednesday, :saturday, :sunday)
schedule.add_exception_rule IceCube::Rule.daily.month_of_year(:february).day_of_month(7, 8, 9, 10, 11, 12, 13, 14)
schedule.add_exception_rule IceCube::Rule.daily.month_of_year(:december).day_of_month(25, 26)
schedule.add_exception_rule IceCube::Rule.daily.month_of_year(:january).day_of_month(1)

We store the result of schedule.to_yaml in our database. At some point in the last few weeks my coworker and I couldn't get exceptions to work anymore. I haven't been able to conclude as of why, but it seems exception_rules are no longer being serialised to to YAML (or Hash).

Test case

schedule = IceCube::Schedule.new(start = Time.utc(2015, 1, 1))
schedule.add_recurrence_rule IceCube::Rule.daily.day(:wednesday, :saturday, :sunday)

schedule.occurrences(2.months.from_now).size
=> 201

schedule.to_yaml
=> "---\n:start_time: 2015-01-01 00:00:00.000000000 Z\n:rrules:\n- :validations:\n    :day:\n    - 3\n    - 6\n    - 0\n  :rule_type: IceCube::DailyRule\n  :interval: 1\n:rtimes: []\n:extimes: []\n"

schedule.add_exception_rule IceCube::Rule.daily.month_of_year(:february).day_of_month(7, 8, 9, 10, 11, 12, 13, 14)
schedule.occurrences(2.months.from_now).size
=> 193

schedule.to_yaml
=> "---\n:start_time: 2015-01-01 00:00:00.000000000 Z\n:rrules:\n- :validations:\n    :day:\n    - 3\n    - 6\n    - 0\n  :rule_type: IceCube::DailyRule\n  :interval: 1\n:rtimes: []\n:extimes: []\n"

As you can see the output of the to_yaml calls is identical.

Env

However I'm experiencing the same issue on regular irb without Rails.

avit commented 8 years ago

Exception rules have been deprecated for a long time. This is based on the iCalendar RFC spec.

The "rules" you have above look like individual dates: you can still do add_exception_time for those.