Simple Ruby/Rails question, doing posted hours ago


#1

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 B.
(ramaza3 on freenode)
http://www.newspiritcompany.com
also checkout alpha version of botverse:
http://www.newspiritcompany.com:8086/universe_home


#2

Berlin B. 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 B.
(ramaza3 on freenode)
http://www.newspiritcompany.com
also checkout alpha version of botverse:
http://www.newspiritcompany.com:8086/universe_home


#3

Berlin B. 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/activesupport/lib/active_support/core_ext/numeric/time_rb.html

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.


#4

Sorry, also look at the method (rails only) distance_of_time_in_words
(ActionView)


#5

Look at distance_of_time_in_words_to_now

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

-Rob

Rob B. http://agileconsultingllc.com
removed_email_address@domain.invalid
+1 513-295-4739