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
3/31/2007.

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.

Thanks!

-Neal

You probably need something line Ruby Temporal Expressions (runt)

http://runt.rubyforge.org/

It does precisely this thing…

Cheers,
Gary.

On 12/10/07, Neal L [email protected] wrote:

3/31/2007.

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.

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)

HTH

Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

On Dec 10, 12:49 pm, “Rick DeNatale” [email protected] wrote:

weekly, monthly, quarterly), I need to be able to figure out the
appreciate any help.

My blog on Rubyhttp://talklikeaduck.denhaven2.com

Rick,

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?

Thanks,
Neal

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs