Skip to content

Instantly share code, notes, and snippets.

@jacobh
Created November 28, 2012 08:59
Show Gist options
  • Save jacobh/4160002 to your computer and use it in GitHub Desktop.
Save jacobh/4160002 to your computer and use it in GitHub Desktop.
little wrapper over moment.js to turn it into a jquery plugin for relative times.
$.fn.relativize = (format='MMM D, YYYY at hh:mma') ->
for date in this
$date = $ date
if $date.attr 'unix_timestamp'
this_moment = moment.unix $date.attr 'unix_timestamp'
else
this_moment = moment $date.text(), FORMAT
$date.attr 'unix_timestamp', this_moment.unix()
$date.text this_moment.fromNow()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment