Skip to content

Instantly share code, notes, and snippets.

@joshbuchea
Forked from cmmartin/moment-filter.js
Last active August 29, 2015 14:16
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 joshbuchea/43f990373d1d4fe0db5f to your computer and use it in GitHub Desktop.
Save joshbuchea/43f990373d1d4fe0db5f to your computer and use it in GitHub Desktop.
// REQUIRES:
// moment.js - https://github.com/moment/momentjs.com
// USAGE:
// {{ someDate | moment: [any moment function] : [param1] : [param2] : [param n]
// EXAMPLES:
// {{ someDate | moment: 'format': 'MMM DD, YYYY' }}
// {{ someDate | moment: 'fromNow' }}
// To call multiple moment functions, you can chain them.
// For example, this converts to UTC and then formats...
// {{ someDate | moment: 'utc' | moment: 'format': 'MMM DD, YYYY' }}
angular.module('myModule').filter('moment', function () {
return function (input, momentFn /*, param1, param2, etc... */) {
var args = Array.prototype.slice.call(arguments, 2),
momentObj = moment(input);
return momentObj[momentFn].apply(momentObj, args);
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment