Skip to content

Instantly share code, notes, and snippets.

@robbyrussell
Created June 29, 2011 19:59
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 robbyrussell/1054781 to your computer and use it in GitHub Desktop.
Save robbyrussell/1054781 to your computer and use it in GitHub Desktop.
Before I start hacking on this myself... anyone have a Ruby method to produce this?
# return strings like:
# "3 months and 14 days" until"...
# "1 year and 11 days until"...
#
def time_until_in_words(future_date)
future_date - Date.today
# magic!
end
@rubysolo
Copy link

What about this?

def time_until_in_words
  "#{ distance_of_time_in_words(Time.now, future_date) } until"
end

@robbyrussell
Copy link
Author

cheeky ;-)

i need very specific dates... not ending it with "about" or "less than"

looks like i'll have to hack on a custom method :-)

@dmarkow
Copy link

dmarkow commented Jun 29, 2011

The dotiw gem will do this. It overrides the default distance_of_time_in_words method. http://rubydoc.info/gems/dotiw/1.1.0/frames

distance_of_time_in_words(Time.now, future_date, false, :only => ["years", "months", "days"])
#=> "3 months and 14 days"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment