Berlin Brown
2006-Mar-30 08:58 UTC
[Rails] Simple Ruby/Rails question, doing posted hours ago
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
Berlin Brown
2006-Mar-30 09:00 UTC
[Rails] Simple Ruby/Rails question, doing posted hours ago
Berlin Brown wrote:> 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. >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
Kev Jackson
2006-Mar-30 09:06 UTC
[Rails] Simple Ruby/Rails question, doing posted hours ago
Berlin Brown wrote:> Berlin Brown wrote: > >> 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. >> > 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.
Kev Jackson
2006-Mar-30 09:08 UTC
[Rails] Simple Ruby/Rails question, doing posted hours ago
Sorry, also look at the method (rails only) distance_of_time_in_words (ActionView)
Rob Biedenharn
2006-Mar-30 09:27 UTC
[Rails] Simple Ruby/Rails question, doing posted hours ago
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 On Mar 30, 2006, at 4:08 AM, Kev Jackson wrote:> Berlin Brown wrote: > >> Berlin Brown wrote: >> >>> 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. >>> >> 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. > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails