Reputation: 49743
Is there a Rails helper or ruby gem similar to distance_of_time_in_words
that takes direction (future/past) into account?
This is how it works
distance_of_time_in_words_to_now 30.days.ago
# "about 1 month"
distance_of_time_in_words_to_now 30.days.from_now
# "about 1 month"
But I'd like to find something that works more like:
distance_of_time_in_words_to_now 30.days.ago
# "about 1 month ago"
distance_of_time_in_words_to_now 30.days.from_now
# "in about 1 month"
Upvotes: 3
Views: 439
Reputation: 13531
According to the docs there isn't.
But, this is trivial enough that you can wrap it in a simple method:
def distance_of_time(time)
if time > Time.now
"in #{distance_of_time_in_words_to_now time}"
else
"#{distance_of_time_in_words_to_now time} ago"
end
end
Upvotes: 6