diff --git a/angular-moment.js b/angular-moment.js index ddb2703..9b48585 100644 --- a/angular-moment.js +++ b/angular-moment.js @@ -563,6 +563,32 @@ amTimeAgoFilter.$stateful = angularMomentConfig.statefulFilters; return amTimeAgoFilter; + }]) + + /** + * @ngdoc filter + * @name angularMoment.filter:amTimeToNow + * @module angularMoment + * @function + */ + .filter('amTimeToNow', ['moment', 'amMoment', 'angularMomentConfig', function (moment, amMoment, angularMomentConfig) { + function amTimeToNowFilter(value, preprocess, suffix) { + if (typeof value === 'undefined' || value === null) { + return ''; + } + + value = amMoment.preprocessDate(value, preprocess); + var date = moment(value); + if (!date.isValid()) { + return ''; + } + + return amMoment.applyTimezone(date).toNow(suffix); + } + + amTimeToNowFilter.$stateful = angularMomentConfig.statefulFilters; + + return amTimeToNowFilter; }]); }