README.rdoc

ice_cube - easy date expansion

gem install ice_cube

ice_cube is a ruby library for easily handling repeated events (schedules).
The API is modeled after iCalendar repeated dates. The power lies in the
ability to specify multiple rules and dates, and have ice_cube quickly
figure out whether the schedule falls on a certain date (.occurs_on?), or
what dates it occurs on (.occurrences, .first, .all_occurrences)

All rules are based off of the schedule's start date. Individual rules
may optionally specify an until date, which is a date that that individual
rule is no longer effective, or a count (which is how many times maximum
you want the rule to be effective)

There are many types of recurrence rules that can be added to a schedule:

Daily

# every day
schedule.add_recurrence_rule Rule.daily
# every third day
schedule.add_recurrence_rule Rule.daily(3)

Monthly (by day of month)

# every month on the first and last days of the month
schedule.add_recurrence_rule Rule.monthly.day_of_month(1, -1)
# every other month on the 15th of the month
schedule.add_recurrence_rule Rule.monthly(2).day_of_month(15)

Monthly (by day of week)

# every month on the first and last tuesdays of the month
schedule.add_recurrence_rule Rule.monthly.day_of_week(:tuesday => [1, -1])
# every other month on the first monday and last tuesday
schedule.add_recurrence_rule Rule.monthly(2).day_of_week(:monday => [1], :tuesday => [-1])
# for programatic convenience (same as above)
schedule.add_recurrence_rule Rule.monthly(2).day_of_week(1 => [1], 2 => [-1])

Yearly (by day of year)

# every year on the 100th day from the beginning and end of the year
schedule.add_recurrence_rule Rule.yearly.day_of_year(100, -100)
# every fourth year on new year's eve
schedule.add_recurrence_rule Rule.yearly(4).day_of_year(-1)

Yearly (by month of year)

# every year on the same day as start_date but in january and february
schedule.add_recurrence_rule Rule.yearly.month_of_year(:january, :februrary)
# every third year in march
schedule.add_recurrence_rule Rule.yearly(3).month_of_year(:march)
# for programatic convenience (same as above)
schedule.add_recurrence_rule Rule.yearly(3).month_of_year(3)

Hourly (by hour of day)

# every hour on the same minute and second as start date
schedule.add_recurrence_rule Rule.hourly
# every other hour, on mondays
schedule.add_recurrence_rule Rule.hourly(2).day(:monday)

Minutely (by minute of hour)

# every 10 minutes
schedule.add_recurrence_rule Rule.minutely(10)
# every hour and a half, on the last tuesday of the month
schedule.add_recurrence_rule Rule.minutely(90).day_of_week(:tuesday => [-1])

License

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the ‘Software’),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.