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

Exceptions, cancellations, force majeure #201

Closed theworkerant closed 10 years ago

theworkerant commented 10 years ago

I'm looking at this gem for the first time and I love it. I've looked at lots of schedule type of gems in the past and this is by far the loveliest— thank you!

I was wondering about "real life" happenings and how they can be handled with this library, or not. For example: can rescheduling an occurrence to the following day be handled gracefully with a combination of #add_exception_time and adding a single extra occurrence?

Also, are there prefabricated Schedules for like... major US holidays or something similar? Would it slow down methods like #remaining_occurrences horribly to have that many rules with a scope of a year or more?

And a long shot... any frontend (javascript/html) libraries that play nice with this gem, using a similar chaining format for specifying recurrence? Do you imagine this gem taking parameters straight from a Rails controller and creating Schedule rules in this way? Any examples?

Cheers!

avit commented 10 years ago

Welcome!

can rescheduling an occurrence to the following day be handled gracefully with a combination of #add_exception_time and adding a single extra occurrence?

Yes, I don't see why not, that's what exceptions are meant for. You can't change the interval "tick" when a scheduled event occurs, but you can mask it with an exception time and add another time in its place.

are there prefabricated Schedules for like... major US holidays or something similar?

No, we don't have anything like that off the shelf. There is a ticket for supporting #from_ical that we expect to merge soon: this could allow you to import from other sources. However, there's no "merge" for schedules if you need to intersect them. At its simplest, this could be just an array of times that you manage yourself, something like this:

holidays.each do |t|
  case t.wday
  when 6 # Saturday, observed on Friday
    schedule.add_exception_time(t)
    schedule.add_recurrence_time(t - 1.day)
  when 7 # Sunday, observed on Monday
    schedule.add_exception_time(t)
    schedule.add_recurrence_time(t + 1.day)
  else
    schedule.add_recurrence_time(t)
  end
end

And a long shot... any frontend (javascript/html) libraries that play nice with this gem, using a similar chaining format for specifying recurrence?

See the wiki! There's a list of related projects and an example model for serializing schedules. :smile: