# Recurring intervals in ruby

**URL:** <https://www.ruby-forum.com/t/recurring-intervals-in-ruby/82495>\
**Category:** Ruby\
**Created:** [January 19, 2007, 4:30pm UTC](https://www.ruby-forum.com/t/recurring-intervals-in-ruby/82495 "2007-01-19T16:30:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![snacktime](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@snacktime](https://www.ruby-forum.com/u/snacktime)\
**Post date:** [January 19, 2007, 4:30pm UTC](https://www.ruby-forum.com/t/recurring-intervals-in-ruby/82495/1 "2007-01-19T16:30:56Z")

</div>

I’m setting about to write a mini language of sorts for defining  
recurring intervals that will be used in a recurring billing  
application. In the past I wrote a simpler version in perl using the  
awsome Date::Manip module, and am looking for the best way to do it in  
ruby. I’m not too concerned about the date calculations themselves  
I’m mainly thinking about how to parse the language. My first thought  
is to just use a parser such as lemon or ragel. Any suggestions? A  
recurring definition would be compiled into a set of billing dates.

Recurring definitions might look something like the following:

- Every month for 12 months starting in 1 month

- Every week for 1 week starting in one week then every month for 12  
months

- Every month until cancelled starting in one week

---

<div class="post-metadata">

**Author:** ![snacktime](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@snacktime](https://www.ruby-forum.com/u/snacktime)\
**Post date:** [September 25, 2007, 10:41pm UTC](https://www.ruby-forum.com/t/recurring-intervals-in-ruby/82495/2 "2007-09-25T22:41:55Z")

</div>

You may to look at the chronic library  
[http://rubyforge.org/projects/chronic](http://rubyforge.org/projects/chronic)

It supports functions similar to what you are looking for.

You can parse things like:

tomorrow  
this monday 07:30  
may 15th  
tomorrow morning  
yesterday at 9:00  
tomorrow at 11pm  
wednesday last week  
1 month from now  
last friday in January

Luis
