Having switched to Ruby on Rails (for now), I was looking for the same functionality as the popular time_since() function and after hours of searching, I found that Ruby has this exact function built in.
No need to download a 3rd party module and add it to your project, simply use:
time_ago_in_words()
time_ago_in_words() does exactly this. Simply pass it a Date or a Time object and it will spit out time since in words. API
distance_of_time_in_words()
This is another cool function I just added to the comment bit. Instead of simply saying how long has passed since comment was added to now, I wanted to say how long has passed after the post was created to when the comment was added. Ex: about 10 minutes after. API
Here’s my code in the post view:
<% for comment in @post.comments %>
... stuff here ...
<%= distance_of_time_in_words(@post.added, comment.added) %>
... stuff here ...
<% end %>
Hope these help out. I spend ridiculous amount of time looking for functions like this so you won’t have to :)
Patrick
over 2 years ago
Dimitry,
I love your site design and layout. Haha, I didn't even need to read the content before I subscribed to your posts. Looking forward to reading your stuff. Also, that link you left on Okdork about the new note sharing application is great. I can't wait till they've got it working.