Quick and Dirty distanceOfTimeInWordsToNow in CoffeeScript

Rails’ best named function. It came handy today:

distanceOfTimeInWords = (dateDiff) ->
  seconds = Math.abs(dateDiff) / 1000
  minutes = seconds / 60
  hours = minutes / 60
  days = hours / 24
  years = days / 365

  words = switch
    when seconds < 45 then "less than a minute"
    when seconds < 90 then "about a minute"
    when minutes < 45 then "#{Math.round minutes} minutes"
    when minutes < 90 then "about an hour"
    when hours < 24 then "about #{Math.round hours} hours"
    when hours < 48 then "a day"
    when days < 30 then "#{Math.floor days} days"
    when days < 60 then "about a month"
    when days < 365 then "#{Math.floor (days/30)} months"
    when years < 2 then "about a year"
    else "#{Math.floor years} years"

  if dateDiff < 0 then "#{words} ago" else "#{words} from now"

distanceOfTimeInWordsToNow = (date) -> distanceOfTimeInWords(date - new Date())

See the gist
(adpted from https://github.com/rmm5t/jquery-timeago/blob/master/jquery.timeago.js)