Skip to content

Instantly share code, notes, and snippets.

@matt-shipman
matt-shipman / gist:8732888
Last active August 29, 2015 13:55
This method takes in a integer or decimal value of time remaining and converts it to natural language. I was unable to find a decent gem so I decided to whip this up quickly. An example of how to use this method: time_to_natural_language(20.days.from_now - Time.now). This method should go in your items_helper.rb or application_helper.rb
def time_to_natural_language(time_left)
if time_left > 0
time_left = time_left.round.to_i
weeks = time_left / 604800
time_left -= weeks * 604800
days = time_left / 86400
time_left -= days * 86400