I''m using distance_of_time_in_words to generate friendly text but not sure it''s the right method to say something was entered "today". Is there an option or other process to use to achieve the text reading "today" rather than about xx hours ago? I''marst ting to think I need to create a new helper method or edit the configs or something. Thanks, DAN -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jason B
2006-Dec-07 08:43 UTC
Re: newbie: How do I convert "about 2 hours ago" to "today"?
I''m not sure if there is an existing way that is clean.... but here is the beginings of a possible solution? SECONDS_IN_DAY = 60*60*24 time_of_post = Time.gm(2000,"jan",1,20,15,1).to_i if (Time.now.to_i - time_of_post) <= SECONDS_IN_DAY # print ''today'' elsif (Time.now.to_i - time_of_post) <= SECONDS_IN_DAY*2 # print ''yesterday'' else # use distance_of_time_in_words end --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
DAN wrote:> I''m using distance_of_time_in_words to generate friendly text but not > sure it''s the right method to say something was entered "today". > > Is there an option or other process to use to achieve the text reading > "today" rather than about xx hours ago? I''marst ting to think I need to > create a new helper method or edit the configs or something.module ApplicationHelper def today_or_time_ago_in_words(time) (time.to_date == Time.now.to_date ? ''today'' : time_ago_in_words(time)) end end>> today_or_time_ago_in_words(Time.new)=> "today">> today_or_time_ago_in_words(Time.gm(2006, "Dec", 1, 11, 0, 0))=> "6 days" Cheers, Mark --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---