Depending on how accurate you actually want, active_support's 72.months
assumes 30 days in a month. Here's a quick comparison of adding 72
months in different libraries:
today_time = Time.now
today_dt = DateTime.now
format = "%Y-%m-%d %H:%M:%S"
puts "Calculate the date of 72 months from today : #{today_time.strftime(format)}"
puts "ActiveSupport (today (Time) + 72.months) : #{(today_time + 72.months).strftime(format)}"
puts "ActiveSupport (today (Time) + 6.years) : #{(today_time + 6.years).strftime(format)}"
puts "Chronic.parse '72 months from now' : #{Chronic.parse('72 months from now').strftime(format)}"
puts "DateTime.now >> 72 : #{(today_dt >> 72).strftime(format)}"
% ruby time-test.rb
Calculate the date of 72 months from today : 2007-09-10 11:32:14
ActiveSupport (today (Time) + 72.months) : 2013-08-09 11:32:14
ActiveSupport (today (Time) + 6.years) : 2013-09-09 23:32:14
Chronic.parse '72 months from now' : 2013-09-10 11:32:14
DateTime.now >> 72 : 2013-09-10 11:32:14
As you can see, there is some disparity. From my perspective, the only ones of
these that are actually correct are the Chronic and the DateTime ones.
Is there a really good date calculation library in ruby that I'm missing?
enjoy,
-jeremy
···
On Tue, Sep 11, 2007 at 01:35:08AM +0900, Phlip wrote:
joep wrote:
> I am writing a small piece that will include a date that needs to be
> compared to the current time.
>
> EX. a = Time.now
> b = db_cert_date + (72 months)
Rails's ActiveSupport package lets you say some_date + 72.months. It's that
simple; the secret unit of exchange is probably seconds.
If this were Brand X, using another platform's low-level library would be
eternal torment, but this is Ruby, so just try require 'active_support'!
You don't have to be using rails you just need the active_support gem
installed.
gem install activesupport
After that just require 'active_support' as Phlip said.
···
On 9/10/07, joep <jplantz@gmail.com> wrote:
On Sep 10, 10:03 am, Phlip <phlip2...@gmail.com> wrote:
> joep wrote:
> > I am writing a small piece that will include a date that needs to be
> > compared to the current time.
>
> > EX. a = Time.now
> > b = db_cert_date + (72 months)
>
> Rails's ActiveSupport package lets you say some_date + 72.months. It's
that
> simple; the secret unit of exchange is probably seconds.
>
> If this were Brand X, using another platform's low-level library would
be
> eternal torment, but this is Ruby, so just try require 'active_support'!
>
> --
> Phlip
Only problem is I'm not using rails. Just straight ruby as a cgi.
--
"Hey brother Christian with your high and mighty errand, Your actions speak
so loud, I can't hear a word you're saying."