Skip to content

Instantly share code, notes, and snippets.

@tomdale
Created April 30, 2014 21:19
Show Gist options
  • Save tomdale/1056193959cd334d84e1 to your computer and use it in GitHub Desktop.
Save tomdale/1056193959cd334d84e1 to your computer and use it in GitHub Desktop.
Date Handlebars helper
// app/helpers/format-date.js
export default Ember.Handlebars.makeBoundHelper(function(value, options) {
if (!value) { return; }
options = options.hash;
var m = moment(value);
var now = moment();
if (options.utc) { m = m.utc(); }
if (options.preventPast) {
if (m.isBefore(now)) {
m = now;
}
}
if (options.fromNow) {
options.from = now;
}
if (options.from) {
return m.from(options.from, options.skipSuffix);
} else {
return m.format(options.format);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment