Forum: Ruby on Rails Simple Ruby/Rails question, doing posted hours ago

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A8e90e6f310e36963dfd432a66e2e558?d=identicon&s=25 Berlin Brown (Guest)
on 2006-03-30 11:01
(Received via mailing list)
I am not the Ruby aficionado yet, if I have created_on ...timestamp.
What is a ruby way of getting the hours/minutes/seconds ago.  is there
some class that has this implemented.

For example:

Posted on 3/28/2006
Show a time with:

posted: 1 day ago
... something along those lines.

--
Berlin Brown
(ramaza3 on freenode)
http://www.newspiritcompany.com
also checkout alpha version of botverse:
http://www.newspiritcompany.com:8086/universe_home
A8e90e6f310e36963dfd432a66e2e558?d=identicon&s=25 Berlin Brown (Guest)
on 2006-03-30 11:01
(Received via mailing list)
Berlin Brown wrote:

> ... something along those lines.
>
Of course, I could just do the math, but I didnt want make sure I wasnt
reinventing the wheel.

--
Berlin Brown
(ramaza3 on freenode)
http://www.newspiritcompany.com
also checkout alpha version of botverse:
http://www.newspiritcompany.com:8086/universe_home
2a0f7bd2c54fbc44329d69555b96f1c5?d=identicon&s=25 Kev Jackson (Guest)
on 2006-03-30 11:07
(Received via mailing list)
Berlin Brown wrote:

>>
>> posted: 1 day ago
>> ... something along those lines.
>>
> Of course, I could just do the math, but I didnt want make sure I
> wasnt reinventing the wheel.
>
api.rubyonrails.org

I think the rails team extended the Time class for this reason
 >>
Module
ActiveSupport::CoreExtensions::Numeric::Time
In:
vendor/rails/activesupport/lib/active_support/core_ext/numeric/time.rb
<http://api.rubyonrails.org/files/vendor/rails/acti...


Enables the use of time calculations and declarations, like 45.minutes +
2.hours + 4.years.

If you need precise date calculations that doesn?t just treat months as
30 days, then have a look at Time#advance.
2a0f7bd2c54fbc44329d69555b96f1c5?d=identicon&s=25 Kev Jackson (Guest)
on 2006-03-30 11:10
(Received via mailing list)
Sorry, also look at the method (rails only) distance_of_time_in_words
(ActionView)
Ef3aa7f7e577ea8cd620462724ddf73b?d=identicon&s=25 Rob Biedenharn (Guest)
on 2006-03-30 11:28
(Received via mailing list)
Look at  distance_of_time_in_words_to_now

http://api.rubyonrails.org/classes/ActionView/Helpers/
DateHelper.html#M000465

-Rob

Rob Biedenharn		http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
+1 513-295-4739
This topic is locked and can not be replied to.