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 received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You probably need something line Ruby Temporal Expressions (runt) http://runt.rubyforge.org/ It does precisely this thing.... Cheers, Gary. Neal L wrote:> 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 received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 12/10/07, Neal L <neal.lober-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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.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/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 10, 12:49 pm, "Rick DeNatale" <rick.denat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 12/10/07, Neal L <neal.lo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > 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. > > 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 Rubyhttp://talklikeaduck.denhaven2.comRick, 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---