diff --git a/README.md b/README.md index 374a585..90221b8 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ Note: To use `amFromUnix`, install angular-moment version 1.0.0-beta.3 or newer ### amUtc filter -Create / switch the current moment object into UTC mode. For example, given a date object in `message.date`, +Create / switch the current moment object into UTC mode. For example, given a date object in `message.date`, the following code will display the time in UTC instead of the local timezone: ```html @@ -134,7 +134,7 @@ Note: To use `amUtcOffset`, install angular-moment version 1.0.0-beta.3 or newer ### amLocal filter -Changes the given moment object to be in the local timezone. Usually used in conjunction with `amUtc` / `amTimezone` +Changes the given moment object to be in the local timezone. Usually used in conjunction with `amUtc` / `amTimezone` for timezone conversion. For example, the following will convert the given UTC date to local time: ```html @@ -195,8 +195,8 @@ For more information about Moment.JS difference function, see the ### amDurationFormat filter -Formats a duration (such as 5 days) in a human readable format. See [Moment.JS documentation](http://momentjs.com/docs/#/durations/creating/) -for a list of supported duration formats, and [`humanize() documentation`](http://momentjs.com/docs/#/durations/humanize/) +Formats a duration (such as 5 days) in a human readable format. If a display format is provided (as third argument), duration is formatted according to this argument instead of being humanized. See [Moment.JS documentation](http://momentjs.com/docs/#/durations/creating/) +for a list of supported duration formats, and [`humanize() documentation`](http://momentjs.com/docs/#/durations/humanize/) for explanation about the formatting algorithm. Example: @@ -207,6 +207,11 @@ Example: Will display the age of the message (e.g. 10 minutes, 1 hour, 2 days, etc). +```html +Next train in {{train.nextDuration | amDurationFormat : 'seconds':undefined:'minutes' }} minutes + +Will display "Next train in 3 minutes" if train.nextDuration is 190. + ### amSubtract filter Subtract values (hours, minutes, seconds ...) from a specified date. diff --git a/angular-moment.js b/angular-moment.js index d7fed90..c2db2ce 100644 --- a/angular-moment.js +++ b/angular-moment.js @@ -593,12 +593,21 @@ * @function */ .filter('amDurationFormat', ['moment', 'angularMomentConfig', function (moment, angularMomentConfig) { - function amDurationFormatFilter(value, format, suffix) { + function amDurationFormatFilter(value, format, suffix, displayFormat) { + var units = ['milliseconds', 'seconds', 'minutes', 'hours', 'days', 'months', 'years']; + var asUnits = units.map(function (unit) { + return 'as' + unit.charAt(0).toUpperCase() + unit.slice(1); + }); + var validDisplayFormats = units.concat(asUnits); + if (isUndefinedOrNull(value)) { return ''; } + if (isUndefinedOrNull(displayFormat) || validDisplayFormats.indexOf(displayFormat) < 0) { + return moment.duration(value, format).humanize(suffix); + } - return moment.duration(value, format).humanize(suffix); + return moment.duration(value, format)[displayFormat](); } amDurationFormatFilter.$stateful = angularMomentConfig.statefulFilters; diff --git a/angular-moment.min.js b/angular-moment.min.js index 7d1e1f5..c22b511 100644 --- a/angular-moment.min.js +++ b/angular-moment.min.js @@ -1,2 +1,2 @@ -"format amd";!function(){"use strict";function a(a){return angular.isUndefined(a)||null===a}function b(){try{return require("moment")}catch(a){throw new Error("Please install moment via npm. Please reference to: https://github.com/urish/angular-moment")}}function c(c,d){if("undefined"==typeof d){if("function"!=typeof require)throw new Error("Moment cannot be found by angular-moment! Please reference to: https://github.com/urish/angular-moment");d=b()}return c.module("angularMoment",[]).constant("angularMomentConfig",{preprocess:null,timezone:null,format:null,statefulFilters:!0}).constant("moment",d).constant("amTimeAgoConfig",{withoutSuffix:!1,serverTime:null,titleFormat:null,fullDateThreshold:null,fullDateFormat:null}).directive("amTimeAgo",["$window","moment","amMoment","amTimeAgoConfig",function(b,d,e,f){return function(g,h,i){function j(){var a;if(p)a=p;else if(f.serverTime){var b=(new Date).getTime(),c=b-v+f.serverTime;a=d(c)}else a=d();return a}function k(){q&&(b.clearTimeout(q),q=null)}function l(a){var c=j().diff(a,"day"),d=t&&c>=t;if(d?h.text(a.format(u)):h.text(a.from(j(),r)),s&&y&&h.attr("title",a.local().format(s)),!d){var e=Math.abs(j().diff(a,"minute")),f=3600;1>e?f=1:60>e?f=30:180>e&&(f=300),q=b.setTimeout(function(){l(a)},1e3*f)}}function m(a){x&&h.attr("datetime",a)}function n(){if(k(),o){var a=e.preprocessDate(o);l(a),m(a.toISOString())}}var o,p,q=null,r=f.withoutSuffix,s=f.titleFormat,t=f.fullDateThreshold,u=f.fullDateFormat,v=(new Date).getTime(),w=i.amTimeAgo,x="TIME"===h[0].nodeName.toUpperCase(),y=!h.attr("title");g.$watch(w,function(b){return a(b)||""===b?(k(),void(o&&(h.text(""),m(""),o=null))):(o=b,void n())}),c.isDefined(i.amFrom)&&g.$watch(i.amFrom,function(b){p=a(b)||""===b?null:d(b),n()}),c.isDefined(i.amWithoutSuffix)&&g.$watch(i.amWithoutSuffix,function(a){"boolean"==typeof a?(r=a,n()):r=f.withoutSuffix}),i.$observe("amFullDateThreshold",function(a){t=a,n()}),i.$observe("amFullDateFormat",function(a){u=a,n()}),g.$on("$destroy",function(){k()}),g.$on("amMoment:localeChanged",function(){n()})}}]).service("amMoment",["moment","$rootScope","$log","angularMomentConfig",function(a,b,d,e){var f=null;this.changeLocale=function(d,e){var f=a.locale(d,e);return c.isDefined(d)&&b.$broadcast("amMoment:localeChanged"),f},this.changeTimezone=function(c){a.tz&&a.tz.setDefault?(a.tz.setDefault(c),b.$broadcast("amMoment:timezoneChanged")):d.warn("angular-moment: changeTimezone() works only with moment-timezone.js v0.3.0 or greater."),e.timezone=c,f=c},this.preprocessDate=function(b){return f!==e.timezone&&this.changeTimezone(e.timezone),e.preprocess?e.preprocess(b):a(!isNaN(parseFloat(b))&&isFinite(b)?parseInt(b,10):b)}}]).filter("amParse",["moment",function(a){return function(b,c){return a(b,c)}}]).filter("amFromUnix",["moment",function(a){return function(b){return a.unix(b)}}]).filter("amUtc",["moment",function(a){return function(b){return a.utc(b)}}]).filter("amUtcOffset",["amMoment",function(a){function b(b,c){return a.preprocessDate(b).utcOffset(c)}return b}]).filter("amLocal",["moment",function(a){return function(b){return a.isMoment(b)?b.local():null}}]).filter("amTimezone",["amMoment","angularMomentConfig","$log",function(a,b,c){function d(b,d){var e=a.preprocessDate(b);return d?e.tz?e.tz(d):(c.warn("angular-moment: named timezone specified but moment.tz() is undefined. Did you forget to include moment-timezone.js ?"),e):e}return d}]).filter("amCalendar",["moment","amMoment","angularMomentConfig",function(b,c,d){function e(b){if(a(b))return"";var d=c.preprocessDate(b);return d.isValid()?d.calendar():""}return e.$stateful=d.statefulFilters,e}]).filter("amDifference",["moment","amMoment","angularMomentConfig",function(b,c,d){function e(d,e,f,g){if(a(d))return"";var h=c.preprocessDate(d),i=a(e)?b():c.preprocessDate(e);return h.isValid()&&i.isValid()?h.diff(i,f,g):""}return e.$stateful=d.statefulFilters,e}]).filter("amDateFormat",["moment","amMoment","angularMomentConfig",function(b,c,d){function e(b,d){if(a(b))return"";var e=c.preprocessDate(b);return e.isValid()?e.format(d):""}return e.$stateful=d.statefulFilters,e}]).filter("amDurationFormat",["moment","angularMomentConfig",function(b,c){function d(c,d,e){return a(c)?"":b.duration(c,d).humanize(e)}return d.$stateful=c.statefulFilters,d}]).filter("amTimeAgo",["moment","amMoment","angularMomentConfig",function(b,c,d){function e(d,e,f){var g,h;return a(d)?"":(d=c.preprocessDate(d),g=b(d),g.isValid()?(h=b(f),!a(f)&&h.isValid()?g.from(h,e):g.fromNow(e)):"")}return e.$stateful=d.statefulFilters,e}]).filter("amSubtract",["moment","angularMomentConfig",function(b,c){function d(c,d,e){return a(c)?"":b(c).subtract(parseInt(d,10),e)}return d.$stateful=c.statefulFilters,d}]).filter("amAdd",["moment","angularMomentConfig",function(b,c){function d(c,d,e){return a(c)?"":b(c).add(parseInt(d,10),e)}return d.$stateful=c.statefulFilters,d}]).filter("amStartOf",["moment","angularMomentConfig",function(b,c){function d(c,d){return a(c)?"":b(c).startOf(d)}return d.$stateful=c.statefulFilters,d}]).filter("amEndOf",["moment","angularMomentConfig",function(b,c){function d(c,d){return a(c)?"":b(c).endOf(d)}return d.$stateful=c.statefulFilters,d}])}"function"==typeof define&&define.amd?define(["angular","moment"],c):"undefined"!=typeof module&&module&&module.exports?(c(require("angular"),require("moment")),module.exports="angularMoment"):c(angular,("undefined"!=typeof global?global:window).moment)}(); +"format amd";!function(){"use strict";function a(a){return angular.isUndefined(a)||null===a}function b(){try{return require("moment")}catch(a){throw new Error("Please install moment via npm. Please reference to: https://github.com/urish/angular-moment")}}function c(c,d){if("undefined"==typeof d){if("function"!=typeof require)throw new Error("Moment cannot be found by angular-moment! Please reference to: https://github.com/urish/angular-moment");d=b()}return c.module("angularMoment",[]).constant("angularMomentConfig",{preprocess:null,timezone:null,format:null,statefulFilters:!0}).constant("moment",d).constant("amTimeAgoConfig",{withoutSuffix:!1,serverTime:null,titleFormat:null,fullDateThreshold:null,fullDateFormat:null}).directive("amTimeAgo",["$window","moment","amMoment","amTimeAgoConfig",function(b,d,e,f){return function(g,h,i){function j(){var a;if(p)a=p;else if(f.serverTime){var b=(new Date).getTime(),c=b-v+f.serverTime;a=d(c)}else a=d();return a}function k(){q&&(b.clearTimeout(q),q=null)}function l(a){var c=j().diff(a,"day"),d=t&&c>=t;if(d?h.text(a.format(u)):h.text(a.from(j(),r)),s&&y&&h.attr("title",a.local().format(s)),!d){var e=Math.abs(j().diff(a,"minute")),f=3600;1>e?f=1:60>e?f=30:180>e&&(f=300),q=b.setTimeout(function(){l(a)},1e3*f)}}function m(a){x&&h.attr("datetime",a)}function n(){if(k(),o){var a=e.preprocessDate(o);l(a),m(a.toISOString())}}var o,p,q=null,r=f.withoutSuffix,s=f.titleFormat,t=f.fullDateThreshold,u=f.fullDateFormat,v=(new Date).getTime(),w=i.amTimeAgo,x="TIME"===h[0].nodeName.toUpperCase(),y=!h.attr("title");g.$watch(w,function(b){return a(b)||""===b?(k(),void(o&&(h.text(""),m(""),o=null))):(o=b,void n())}),c.isDefined(i.amFrom)&&g.$watch(i.amFrom,function(b){p=a(b)||""===b?null:d(b),n()}),c.isDefined(i.amWithoutSuffix)&&g.$watch(i.amWithoutSuffix,function(a){"boolean"==typeof a?(r=a,n()):r=f.withoutSuffix}),i.$observe("amFullDateThreshold",function(a){t=a,n()}),i.$observe("amFullDateFormat",function(a){u=a,n()}),g.$on("$destroy",function(){k()}),g.$on("amMoment:localeChanged",function(){n()})}}]).service("amMoment",["moment","$rootScope","$log","angularMomentConfig",function(a,b,d,e){var f=null;this.changeLocale=function(d,e){var f=a.locale(d,e);return c.isDefined(d)&&b.$broadcast("amMoment:localeChanged"),f},this.changeTimezone=function(c){a.tz&&a.tz.setDefault?(a.tz.setDefault(c),b.$broadcast("amMoment:timezoneChanged")):d.warn("angular-moment: changeTimezone() works only with moment-timezone.js v0.3.0 or greater."),e.timezone=c,f=c},this.preprocessDate=function(b){return f!==e.timezone&&this.changeTimezone(e.timezone),e.preprocess?e.preprocess(b):a(!isNaN(parseFloat(b))&&isFinite(b)?parseInt(b,10):b)}}]).filter("amParse",["moment",function(a){return function(b,c){return a(b,c)}}]).filter("amFromUnix",["moment",function(a){return function(b){return a.unix(b)}}]).filter("amUtc",["moment",function(a){return function(b){return a.utc(b)}}]).filter("amUtcOffset",["amMoment",function(a){function b(b,c){return a.preprocessDate(b).utcOffset(c)}return b}]).filter("amLocal",["moment",function(a){return function(b){return a.isMoment(b)?b.local():null}}]).filter("amTimezone",["amMoment","angularMomentConfig","$log",function(a,b,c){function d(b,d){var e=a.preprocessDate(b);return d?e.tz?e.tz(d):(c.warn("angular-moment: named timezone specified but moment.tz() is undefined. Did you forget to include moment-timezone.js ?"),e):e}return d}]).filter("amCalendar",["moment","amMoment","angularMomentConfig",function(b,c,d){function e(b){if(a(b))return"";var d=c.preprocessDate(b);return d.isValid()?d.calendar():""}return e.$stateful=d.statefulFilters,e}]).filter("amDifference",["moment","amMoment","angularMomentConfig",function(b,c,d){function e(d,e,f,g){if(a(d))return"";var h=c.preprocessDate(d),i=a(e)?b():c.preprocessDate(e);return h.isValid()&&i.isValid()?h.diff(i,f,g):""}return e.$stateful=d.statefulFilters,e}]).filter("amDateFormat",["moment","amMoment","angularMomentConfig",function(b,c,d){function e(b,d){if(a(b))return"";var e=c.preprocessDate(b);return e.isValid()?e.format(d):""}return e.$stateful=d.statefulFilters,e}]).filter("amDurationFormat",["moment","angularMomentConfig",function(b,c){function d(c,d,e,f){var g=["milliseconds","seconds","minutes","hours","days","months","years"],h=g.map(function(a){return"as"+a.charAt(0).toUpperCase()+a.slice(1)}),i=g.concat(h);return a(c)?"":a(f)||i.indexOf(f)<0?b.duration(c,d).humanize(e):b.duration(c,d)[f]()}return d.$stateful=c.statefulFilters,d}]).filter("amTimeAgo",["moment","amMoment","angularMomentConfig",function(b,c,d){function e(d,e,f){var g,h;return a(d)?"":(d=c.preprocessDate(d),g=b(d),g.isValid()?(h=b(f),!a(f)&&h.isValid()?g.from(h,e):g.fromNow(e)):"")}return e.$stateful=d.statefulFilters,e}]).filter("amSubtract",["moment","angularMomentConfig",function(b,c){function d(c,d,e){return a(c)?"":b(c).subtract(parseInt(d,10),e)}return d.$stateful=c.statefulFilters,d}]).filter("amAdd",["moment","angularMomentConfig",function(b,c){function d(c,d,e){return a(c)?"":b(c).add(parseInt(d,10),e)}return d.$stateful=c.statefulFilters,d}]).filter("amStartOf",["moment","angularMomentConfig",function(b,c){function d(c,d){return a(c)?"":b(c).startOf(d)}return d.$stateful=c.statefulFilters,d}]).filter("amEndOf",["moment","angularMomentConfig",function(b,c){function d(c,d){return a(c)?"":b(c).endOf(d)}return d.$stateful=c.statefulFilters,d}])}"function"==typeof define&&define.amd?define(["angular","moment"],c):"undefined"!=typeof module&&module&&module.exports?(c(require("angular"),require("moment")),module.exports="angularMoment"):c(angular,("undefined"!=typeof global?global:window).moment)}(); //# sourceMappingURL=angular-moment.min.js.map \ No newline at end of file diff --git a/angular-moment.min.js.map b/angular-moment.min.js.map index fb20b30..8a17d55 100644 --- a/angular-moment.min.js.map +++ b/angular-moment.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["angular-moment.js"],"names":["isUndefinedOrNull","val","angular","isUndefined","requireMoment","require","e","Error","angularMoment","moment","module","constant","preprocess","timezone","format","statefulFilters","withoutSuffix","serverTime","titleFormat","fullDateThreshold","fullDateFormat","directive","$window","amMoment","amTimeAgoConfig","scope","element","attr","getNow","now","currentFrom","localNow","Date","getTime","nowMillis","localDate","cancelTimer","activeTimeout","clearTimeout","updateTime","momentInstance","daysAgo","diff","showFullDate","text","from","setTitleTime","local","howOld","Math","abs","secondsUntilUpdate","setTimeout","updateDateTimeAttr","value","isTimeElement","updateMoment","currentValue","momentValue","preprocessDate","toISOString","modelName","amTimeAgo","nodeName","toUpperCase","$watch","isDefined","amFrom","amWithoutSuffix","$observe","newValue","$on","service","$rootScope","$log","angularMomentConfig","defaultTimezone","this","changeLocale","locale","customization","result","$broadcast","changeTimezone","tz","setDefault","warn","isNaN","parseFloat","isFinite","parseInt","filter","unix","utc","amUtcOffset","offset","utcOffset","isMoment","amTimezone","aMoment","amCalendarFilter","date","isValid","calendar","$stateful","amDifferenceFilter","otherValue","unit","usePrecision","date2","amDateFormatFilter","amDurationFormatFilter","suffix","duration","humanize","amTimeAgoFilter","dateFrom","fromNow","amSubtractFilter","amount","type","subtract","amAddFilter","add","amStartOfFilter","startOf","amEndOfFilter","endOf","define","amd","exports","global","window"],"mappings":"AAEA,cAGA,WACC,YAEA,SAASA,GAAkBC,GAC1B,MAAOC,SAAQC,YAAYF,IAAgB,OAARA,EAGpC,QAASG,KACR,IACC,MAAOC,SAAQ,UACd,MAAOC,GACR,KAAM,IAAIC,OAAM,gGAIlB,QAASC,GAAcN,EAASO,GAE/B,GAAqB,mBAAXA,GAAwB,CACjC,GAAsB,kBAAZJ,SAGT,KAAM,IAAIE,OAAM,yGAFhBE,GAASL,IAaX,MAAOF,GAAQQ,OAAO,oBASpBC,SAAS,uBAiBTC,WAAY,KAcZC,SAAU,KAaVC,OAAQ,KAaRC,iBAAiB,IAUjBJ,SAAS,SAAUF,GAUnBE,SAAS,mBAUTK,eAAe,EAYfC,WAAY,KAYZC,YAAa,KAYbC,kBAAmB,KAWnBC,eAAgB,OAUhBC,UAAU,aAAc,UAAW,SAAU,WAAY,kBAAmB,SAAUC,EAASb,EAAQc,EAAUC,GAEjH,MAAO,UAAUC,EAAOC,EAASC,GAahC,QAASC,KACR,GAAIC,EACJ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MAFAF,GAAiBd,UAAY7B,EAAoB5D,gBAE1CuG,KASP3B,OAAO,SAAU,SAAU,sBAAuB,SAAUlF,EAAQkE,GACpE,QAAS+C,GAAYpE,EAAOiE,EAAQC,GAEnC,MAAIxH,GAAkBsD,GACd,GAGD7C,EAAO6C,GAAOqE,IAAIjC,SAAS6B,EAAQ,IAAKC,GAKhD,MAFAE,GAAYlB,UAAY7B,EAAoB5D,gBAErC2G,KASP/B,OAAO,aAAc,SAAU,sBAAuB,SAAUlF,EAAQkE,GACxE,QAASiD,GAAgBtE,EAAOkE,GAE/B,MAAIxH,GAAkBsD,GACd,GAGD7C,EAAO6C,GAAOuE,QAAQL,GAK9B,MAFAI,GAAgBpB,UAAY7B,EAAoB5D,gBAEzC6G,KASPjC,OAAO,WAAY,SAAU,sBAAuB,SAAUlF,EAAQkE,GACtE,QAASmD,GAAcxE,EAAOkE,GAE7B,MAAIxH,GAAkBsD,GACd,GAGD7C,EAAO6C,GAAOyE,MAAMP,GAK5B,MAFAM,GAActB,UAAY7B,EAAoB5D,gBAEvC+G,KAIY,kBAAXE,SAAyBA,OAAOC,IAC1CD,QAAQ,UAAW,UAAWxH,GACF,mBAAXE,SAA0BA,QAAUA,OAAOwH,SAC5D1H,EAAcH,QAAQ,WAAYA,QAAQ,WAC1CK,OAAOwH,QAAU,iBAEjB1H,EAAcN,SAA4B,mBAAXiI,QAAyBA,OAASC,QAAQ3H","file":"angular-moment.min.js"} \ No newline at end of file +{"version":3,"sources":["angular-moment.js"],"names":["isUndefinedOrNull","val","angular","isUndefined","requireMoment","require","e","Error","angularMoment","moment","module","constant","preprocess","timezone","format","statefulFilters","withoutSuffix","serverTime","titleFormat","fullDateThreshold","fullDateFormat","directive","$window","amMoment","amTimeAgoConfig","scope","element","attr","getNow","now","currentFrom","localNow","Date","getTime","nowMillis","localDate","cancelTimer","activeTimeout","clearTimeout","updateTime","momentInstance","daysAgo","diff","showFullDate","text","from","setTitleTime","local","howOld","Math","abs","secondsUntilUpdate","setTimeout","updateDateTimeAttr","value","isTimeElement","updateMoment","currentValue","momentValue","preprocessDate","toISOString","modelName","amTimeAgo","nodeName","toUpperCase","$watch","isDefined","amFrom","amWithoutSuffix","$observe","newValue","$on","service","$rootScope","$log","angularMomentConfig","defaultTimezone","this","changeLocale","locale","customization","result","$broadcast","changeTimezone","tz","setDefault","warn","isNaN","parseFloat","isFinite","parseInt","filter","unix","utc","amUtcOffset","offset","utcOffset","isMoment","amTimezone","aMoment","amCalendarFilter","date","isValid","calendar","$stateful","amDifferenceFilter","otherValue","unit","usePrecision","date2","amDateFormatFilter","amDurationFormatFilter","suffix","displayFormat","units","asUnits","map","charAt","slice","validDisplayFormats","concat","indexOf","duration","humanize","amTimeAgoFilter","dateFrom","fromNow","amSubtractFilter","amount","type","subtract","amAddFilter","add","amStartOfFilter","startOf","amEndOfFilter","endOf","define","amd","exports","global","window"],"mappings":"AAEA,cAGA,WACC,YAEA,SAASA,GAAkBC,GAC1B,MAAOC,SAAQC,YAAYF,IAAgB,OAARA,EAGpC,QAASG,KACR,IACC,MAAOC,SAAQ,UACd,MAAOC,GACR,KAAM,IAAIC,OAAM,gGAIlB,QAASC,GAAcN,EAASO,GAE/B,GAAqB,mBAAXA,GAAwB,CACjC,GAAsB,kBAAZJ,SAGT,KAAM,IAAIE,OAAM,yGAFhBE,GAASL,IAaX,MAAOF,GAAQQ,OAAO,oBASpBC,SAAS,uBAiBTC,WAAY,KAcZC,SAAU,KAaVC,OAAQ,KAaRC,iBAAiB,IAUjBJ,SAAS,SAAUF,GAUnBE,SAAS,mBAUTK,eAAe,EAYfC,WAAY,KAYZC,YAAa,KAYbC,kBAAmB,KAWnBC,eAAgB,OAUhBC,UAAU,aAAc,UAAW,SAAU,WAAY,kBAAmB,SAAUC,EAASb,EAAQc,EAAUC,GAEjH,MAAO,UAAUC,EAAOC,EAASC,GAahC,QAASC,KACR,GAAIC,EACJ,IAAIC,EACHD,EAAMC,MACA,IAAIN,EAAgBP,WAAY,CACtC,G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AaT,MAFAY,GAAgBpB,UAAY7B,EAAoB5D,gBAEzC6G,KASPjC,OAAO,cAAe,SAAU,sBAAuB,SAAUlF,EAAQkE,GACzE,QAASoD,GAAiBzE,EAAO0E,EAAQC,GAExC,MAAIjI,GAAkBsD,GACd,GAGD7C,EAAO6C,GAAO4E,SAASxC,SAASsC,EAAQ,IAAKC,GAKrD,MAFAF,GAAiBvB,UAAY7B,EAAoB5D,gBAE1CgH,KASPpC,OAAO,SAAU,SAAU,sBAAuB,SAAUlF,EAAQkE,GACpE,QAASwD,GAAY7E,EAAO0E,EAAQC,GAEnC,MAAIjI,GAAkBsD,GACd,GAGD7C,EAAO6C,GAAO8E,IAAI1C,SAASsC,EAAQ,IAAKC,GAKhD,MAFAE,GAAY3B,UAAY7B,EAAoB5D,gBAErCoH,KASPxC,OAAO,aAAc,SAAU,sBAAuB,SAAUlF,EAAQkE,GACxE,QAAS0D,GAAgB/E,EAAO2E,GAE/B,MAAIjI,GAAkBsD,GACd,GAGD7C,EAAO6C,GAAOgF,QAAQL,GAK9B,MAFAI,GAAgB7B,UAAY7B,EAAoB5D,gBAEzCsH,KASP1C,OAAO,WAAY,SAAU,sBAAuB,SAAUlF,EAAQkE,GACtE,QAAS4D,GAAcjF,EAAO2E,GAE7B,MAAIjI,GAAkBsD,GACd,GAGD7C,EAAO6C,GAAOkF,MAAMP,GAK5B,MAFAM,GAAc/B,UAAY7B,EAAoB5D,gBAEvCwH,KAIY,kBAAXE,SAAyBA,OAAOC,IAC1CD,QAAQ,UAAW,UAAWjI,GACF,mBAAXE,SAA0BA,QAAUA,OAAOiI,SAC5DnI,EAAcH,QAAQ,WAAYA,QAAQ,WAC1CK,OAAOiI,QAAU,iBAEjBnI,EAAcN,SAA4B,mBAAX0I,QAAyBA,OAASC,QAAQpI","file":"angular-moment.min.js"} \ No newline at end of file diff --git a/tests.js b/tests.js index b63522a..c96af8a 100644 --- a/tests.js +++ b/tests.js @@ -681,6 +681,14 @@ describe('module angularMoment', function () { it('should gracefully handle undefined values for duration', function () { expect(amDurationFormat(undefined, 'minutes')).toBe(''); }); + + it('should support display formatting', function () { + expect(amDurationFormat(130, 'seconds', undefined, 'minutes')).toBe(2); + }); + + it('should gracefully handle bad display format', function () { + expect(amDurationFormat(120, 'seconds', undefined, 'foo')).toBe('2 minutes'); + }); });