rubyrecurring-eventsice-cube

Ruby/ice_cube: Exclude whole day for hourly recurring event


Just started playing around with ice_cube I've got a weekly schedule (with a granularity of half an hour) created

schedule = IceCube::Schedule.new(Time.now.change(:min => 30))

with several rules (let's say 20) such as e.g.

IceCube::Rule.weekly.day(:tuesday).hour_of_day(14).minute_of_hour(30)

or

IceCube::Rule.weekly.day(:wednesday).hour_of_day(10).minute_of_hour(0)

Now I'd like to exclude a full day, which would subsequently exclude all occurrences during this full day.

I've tried

schedule.add_exception_date [DATE]

but it seems that my exception has to match the event exactly.

Is there a way to get this done without looping through all rules and creating exception for the exact times for the date specified?


Update:

To make a better example:

Weekly schedule:
  * Every monday at 14:40
  * Every monday at 15:00
  * Every thursday at 16:00 
  * Every saturday at 10:00

Exception date:
  Tuesday, 13th of September 2011

=> For the week from Monday 12th to Sunday 18th I'd like to get only the occurrences on Thursday and Saturday.

One solution could look something like this, but it's a little icky:

schedule    = IceCube::Schedule.from_yaml([PERSISTED SCHEDULE])
occurrences = schedule.occurrences_between([START TIME], [END TIME])
exceptions  = schedule.exdates.map(&:to_date)
occurrences.reject {|occurrence|
  exceptions.include?(occurrence.to_date)
}

—Any better ideas?


Solution

  • Since there seems to be no other solution and in order to close this question, here’s what I'm using (as described in an update to the original question above already):

    schedule    = IceCube::Schedule.from_yaml([PERSISTED SCHEDULE])
    occurrences = schedule.occurrences_between([START TIME], [END TIME])
    exceptions  = schedule.exdates.map(&:to_date)
    occurrences.reject {|occurrence|
      exceptions.include?(occurrence.to_date)
    }