# Recurrence 0.1.0

**URL:** <https://www.ruby-forum.com/t/recurrence-0-1-0/147645>\
**Category:** Ruby\
**Created:** [September 3, 2008, 11:02pm UTC](https://www.ruby-forum.com/t/recurrence-0-1-0/147645 "2008-09-03T23:02:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![edvardm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c37758/32.png) [@edvardm](https://www.ruby-forum.com/u/edvardm)\
**Post date:** [September 3, 2008, 11:02pm UTC](https://www.ruby-forum.com/t/recurrence-0-1-0/147645/1 "2008-09-03T23:02:18Z")

</div>

git clone git://github.com/EdvardM/recurrence.git

From the README:

- Recurrence

\*\* Overview

Recurrence provides a simple class for handling recurring,  
time-associated  
objects. The goal is to create a general-purpose,  
loosely coupled class library to provide common functionality for events  
occurring at predetermined intervals.

Short example:

require ‘recurrence’

first\_of\_june = [2008, 6, 1]  
r = Recurrence.new(first\_of\_june, :every\_other =\> :week, :until =\>  
‘2010-06-01’)

my\_cal = MyCalendar.new\_default  
my\_cal.each\_day { |date|  
time = Time.parse(date) # assuming date can be parsed with  
Time.parse  
puts ‘Yay! today is the day!’ if r.recurs\_on?(time)  
}

\*\* Set-like operations

Real power of Recurrence lies in it’s support for set-like operations  
+join+,  
+intersect+, +diff+ and +complement+. For example,  
given the start date of 2008-06-01, recur something every thursday and  
friday:

require ‘recurrence’

start\_date = ‘2008-06-01’  
r1 = Recurrence.new(start\_date, :every =\> :thursday)  
r2 = Recurrence.new(start\_date, :every =\> :friday)  
r = r1.join(r2)

Another example, a tad contrived perhaps:

# Recur something every friday, except if it is last friday of the

month:

dow = :friday  
r1 = Recurrence.new(:epoch, :every =\> dow)  
r2 = Recurrence.new(:epoch, :every\_last =\> dow, :of =\> :month)

r = r1.diff(r2)

Nested set-like operations are also possible. So, for arbitrary  
recurrences a  
and b and any time t, the following should always apply:

r1 = (a.join(b)).complement  
r2 = (a.complement).intersect(b.complement)

r1.recurs\_on?(t) == r2.recurs\_on?(t) # De Morgan’s law - complement of  
a  
union is the same as intersection of the complements

See RecurrenceBase::SetOperations for more.

\*\* Installation

Enter

rake gem

on the command line in the same directory as this README file, it should  
produce the gem under the pkg directory.  
Then you should be able to say

sudo gem install pkg/recurrence\*.gem

to install the gem to your local system.

KTHXBAI

\*\* License

MIT (see MIT-LICENSE)

–

# Ed
