Simple Recurrence Rule for IceCube

  • Mar 17

When it comes to recurrence event for Rails, IceCube is probably the first choice. While it is very good at calculating recurrence, saving recurrence rule is not trivial. And a UI for complicated recurrences is difficult. In any case, this is a simplified recurrence rule for IceCube. It might help in some way.

IceCube models recurrence based on rrule of iCal. Therefore, these are the basic rules:

FREQ: D(daily), W(weekly), M(monthly), Y(yearly)
COUNT: #x where x is number
INTERVAL: +x where x is interval
BY use dot (.)
  BYDAY: .SU, .MO, .TU, .WE, .TH, .FR, .SA, .1FR, .-1FR, .20MO
  BYMONTHDAY: .D1-31 (+/-)
  BYMONTH: .M1-12 (+/-)
  BYYEARDAY: .Y1, Y100, Y200
  BYWEEKNO: .W20 (week number)

Week starts at 0 (Sunday), month and year at 1.

As a result, daily for 10 occurrences look like this:


And 'Every Friday the 13th' is


Here is the code for conversion between this simplified rule and IceCube. Many more examples and test are included.

Such simplified rules can be saved in text field in database and used in HTML select options. Multiple recurrence rules can also be put together in one sentence separated by space.

Hope this approach can ease the problem of using IceCube in Rails application.