public
Description: RecurringEvent: A ruby library to aid in describing recurrent or patterned sets of dates.
Homepage: http://code.whiteink.com/repos/recurring_event/
Clone URL: git://github.com/nickstenning/recurring_event.git
name age message
file README.markdown Mon Mar 24 17:09:27 -0700 2008 Rename README to README.markdown for github goo... [nickstenning]
file Rakefile Tue May 08 08:47:18 -0700 2007 Initial import [nickstenning]
directory lib/ Wed May 09 06:07:56 -0700 2007 Modulize Expression functionality The Express... [nickstenning]
directory spec/ Wed May 09 06:07:56 -0700 2007 Modulize Expression functionality The Express... [nickstenning]
directory vendor/ Tue May 08 08:47:18 -0700 2007 Initial import [nickstenning]
README.markdown

RecurringEvent - An(other) implementation of Fowler's recurring event pattern.

RecurringEvent is an attempt to make a more rubyish version of Martin Fowler's Recurring Event pattern, a la Runt. Where Runt has DIMonth, REYear, and so on, RecurringEvent has the following:

include RecurringEvent
expr = ( Day.in_month(1) | Day.range_each_month(21..28) )
expr &= Month.range_each_year(1..6)

expr.include? Date.new( 2006, 01, 01 ) # => true
expr.include? Date.new( 2006, 01, 02 ) # => false
expr.include? Date.new( 2006, 04, 23 ) # => true
expr.include? Date.new( 2006, 07, 01 ) # => false
expr.include? Date.new( 2006, 07, 23 ) # => false

In case you didn't catch that, those two lines at the top set up a conditional expression which will only #include? dates which are ((the first day of the month OR the 21st to 28th of the month) AND in January through to July). But RecurringEvent goes further than that. Thanks to the hands-off fashion in which all this is achieved, we can mix in dates and date ranges with the RecurringEvent expressions:

include RecurringEvent

expr = Day.in_week(3) | Date.new(2006, 07, 04) 
expr |= Date.new(2006,10,01)..Date.new(2006,10,15)

That expression will match every Wednesday, as well as Independence Day and the 1st to 15th of August in 2006.