Skip to content

Instantly share code, notes, and snippets.

View sulf's full-sized avatar

Ulf Schwekendiek sulf

  • San Francisco, CA
View GitHub Profile
@sulf
sulf / time.js.coffee
Created August 19, 2011 20:16
Rails helper time_ago_in_words() and distance_of_time_in_words() translated into coffee script. Check out http://apidock.com/rails/ActionView/Helpers/DateHelper/distance_of_time_in_words for the rails documentation.
time_ago_in_words = (from_time, include_seconds) ->
include_seconds ?= false
App.distance_of_time_in_words(from_time, Date.now(), include_seconds)
distance_of_time_in_words = (from_time, to_time, include_seconds) ->
include_seconds ?= false
to_time ?= 0
distance_in_minutes = Math.round(Math.abs(to_time - from_time) / 60 / 1000)
distance_in_seconds = Math.round(Math.abs(to_time - from_time) / 1000)