Skip to content

Instantly share code, notes, and snippets.

@gregblass
Last active October 4, 2017 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregblass/46003b15a3290ff97f6f to your computer and use it in GitHub Desktop.
Save gregblass/46003b15a3290ff97f6f to your computer and use it in GitHub Desktop.
A better, Facebook-style activity time_ago_in_words
def better_time_ago_in_words(date_time)
if date_time < 2.days.ago
"#{date_time.strftime('%B %e')} at #{date_time.strftime('%l:%M%P')}"
elsif date_time < 1.day.ago
"Yesterday at #{date_time.strftime('%l:%M%P')}"
else
time_ago_in_words(date_time)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment