I’m trying to use time.ago using standalone ActiveSupport, required thus:
ruby
require 'active_support/core_ext/date_time/calculations'
If I try to use it as advised:
ruby
time = Chronic.parse(time_string)
time.ago
I get this error:
ArgumentError - wrong number of arguments (0 for 1):
/home/user/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.0/lib/active_support/core_ext/date_time/calculations.rb:61:in `ago'
and if I supply an argument, thus:
ruby
time.ago DateTime.now
I get this one, which I don’t understand at all:
NoMethodError - undefined method `-@' for #<DateTime:0x00000001f18168>:
/home/passcod/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.0/lib/active_support/core_ext/date_time/calculations.rb:62:in `ago'
The
agomethod is designed for you to be able to add a number of seconds (or other time units) to the current time, e.g.10.minutes.ago.Supplying a full date isn’t supported and doesn’t make sense as far as I can tell – what would 23rd January 2012 at 2pm.ago mean ?