Re: easiest way to set future date
- From: "Gene Tani" <gene.tani@xxxxxxxxx>
- Date: 30 Oct 2005 07:18:05 -0800
have you looked at Active Support:
http://as.rubyonrails.com/
(altho I have a hazy recollection that the months ago calculations
aren't based on exact days, check that)
enspired wrote:
> I need to calculate an end date based on a start date (Date.today + #
> of trial days). Basically, the app allows different services to be
> purchased for different durations. So one service might be a year while
> another might be 6 months. What's the best way to accomplish this,
> keeping in mind that service durations could be configured in days,
> months or years (although I could just make it months if adhering to
> YAGNI)?
>
> def before_create
> # set service_start_date/service_end_date based on service_level
> trial_days = self.service_level.trial_days || 0
> start_date = Date.today + (trial_days * (24 * 60 * 60))
> duration = self.service_level.duration # number of units * frequency
> frequency = self.service_level.frequency # can be 'D', 'M', 'Y'
>
> # determine end_date
> #end_date = start_date (???)
>
> self.service_start_date = start_date
> self.service_end_date = end_date
> end
.
- Prev by Date: C# attributes in Ruby?
- Next by Date: Re: Kernel#require accepting multiple arguments?
- Previous by thread: C# attributes in Ruby?
- Next by thread: Which Ruby Version?
- Index(es):