# Recurrence 0.1.0, Ruby library for recurring stuff

**URL:** <https://www.ruby-forum.com/t/recurrence-0-1-0-ruby-library-for-recurring-stuff/147678>\
**Category:** Ruby\
**Created:** [September 4, 2008, 7:15am UTC](https://www.ruby-forum.com/t/recurrence-0-1-0-ruby-library-for-recurring-stuff/147678 "2008-09-04T07:15:52Z")\
**Posts on this page:** 4\
**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 4, 2008, 7:15am UTC](https://www.ruby-forum.com/t/recurrence-0-1-0-ruby-library-for-recurring-stuff/147678/1 "2008-09-04T07:15:52Z")

</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)

---

<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 4, 2008, 8:25pm UTC](https://www.ruby-forum.com/t/recurrence-0-1-0-ruby-library-for-recurring-stuff/147678/2 "2008-09-04T20:25:46Z")

</div>

On Sep 3, 2008, at 22:09 , EdvardM wrote:

> time = Time.parse(date) # assuming date can be parsed with  
> Time.parse  
> puts ‘Yay! today is the day!’ if r.recurs\_on?(time)  
> }

shorter, more efficient example:

require ‘date’

(Date.civil(2008, 6, 1)…Date.civil(2010, 6, 1)).step(14) do |d|  
puts d  
end

> \*\* Set-like operations

why? when would you need/want this?

> \*\* Installation

> rake gem  
> sudo gem install pkg/recurrence\*.gem

you’re forgetting about rubyforge. you really should release real gems.

> **[Don't forget about RubyForge - RubyFlow](https://rubyflow.com/p/666)**
>
> Dont forget about RubyForge

---

<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 5, 2008, 2:58pm UTC](https://www.ruby-forum.com/t/recurrence-0-1-0-ruby-library-for-recurring-stuff/147678/3 "2008-09-05T14:58:06Z")

</div>

> \*\* Set-like operations
> 
> why? when would you need/want this?

There’s a project similar to the GP’s called Runt that I used at work  
for a  
calendaring program. This program had to handle expressions like “every  
15th and 20th business day, effective July 20th, 1987”. I used Runt’s  
set-like operations for that example.

James

---

<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 10, 2008, 11:05pm UTC](https://www.ruby-forum.com/t/recurrence-0-1-0-ruby-library-for-recurring-stuff/147678/4 "2008-09-10T23:05:25Z")

</div>

On Fri, Sep 5, 2008 at 8:51 AM, James H.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> 

What I’d really love for my current project is a library for recurring  
events which had the same view of how to define them as rfc 2445 a.k.a.  
iCalendar

There are a couple of gems which can parse and produce iCalendar format,  
but  
neither of them handles the semantics of recurring events.

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)
