Recurring Billing

Hi all,

I'm working on an invoicing program and need a bit of help working
with dates. Given a start date, end date, and frequency (i.e.,
weekly, monthly, quarterly), I need to be able to figure out the
"window" that a certain date fits in.

For example, if charges are monthly and start on 1/1/07, I need a way
to figure out that 3/4/2007 is in the window of 3/1/2007 through

Or if charges are weekly and start on 1/1/07, I need a way to figure
out that 1/10/2007 is in the window of 1/7/2007 through 1/13/2007.

I'm sure Ruby/Rails has a clever way to handle this, and would really
appreciate any help.



You probably need something line Ruby Temporal Expressions (runt)

It does precisely this thing....


Neal L wrote:

Well you need some date objects.

start_date = Date.parse("1/7/2007")
end_date = Date.parse("1/13/2007")
date = Date.parse("1/10/2007")

These are just examples of how to get date objects.

Now you can do a range test:

  if (start_date..end_date).include?(date)

using three dots instead of two to specify the range gives a range
which excludes the last value so another way to do this could be:

  if (start_date..start_date + 7).include?(date)



Thanks for the help! The underlying question though is: how do I
figure out the start and end dates of the range to test against?