From: Iskren Chernev Date: Thu, 24 Sep 2015 04:36:28 +0000 (-0700) Subject: Fix wrong humanize format with weird custom relative thresholds X-Git-Tag: 2.11.0~70^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa34905e297ac3b9d12f7d1d11449faa362ef6db;p=thirdparty%2Fmoment.git Fix wrong humanize format with weird custom relative thresholds --- diff --git a/src/lib/duration/humanize.js b/src/lib/duration/humanize.js index d6dd83b04..eb03311de 100644 --- a/src/lib/duration/humanize.js +++ b/src/lib/duration/humanize.js @@ -24,15 +24,15 @@ function relativeTime (posNegDuration, withoutSuffix, locale) { var years = round(duration.as('y')); var a = seconds < thresholds.s && ['s', seconds] || - minutes === 1 && ['m'] || + minutes <= 1 && ['m'] || minutes < thresholds.m && ['mm', minutes] || - hours === 1 && ['h'] || + hours <= 1 && ['h'] || hours < thresholds.h && ['hh', hours] || - days === 1 && ['d'] || + days <= 1 && ['d'] || days < thresholds.d && ['dd', days] || - months === 1 && ['M'] || + months <= 1 && ['M'] || months < thresholds.M && ['MM', months] || - years === 1 && ['y'] || ['yy', years]; + years <= 1 && ['y'] || ['yy', years]; a[2] = withoutSuffix; a[3] = +posNegDuration > 0; diff --git a/src/test/moment/relative_time.js b/src/test/moment/relative_time.js index 0270ab175..b2b52351e 100644 --- a/src/test/moment/relative_time.js +++ b/src/test/moment/relative_time.js @@ -80,10 +80,21 @@ test('default thresholds toNow', function (assert) { }); test('custom thresholds', function (assert) { + var a; + + // Seconds to minute threshold, under 30 + moment.relativeTimeThreshold('s', 25); + + a = moment(); + a.subtract(24, 'seconds'); + assert.equal(a.fromNow(), 'a few seconds ago', 'Below custom seconds to minute threshold, s < 30'); + a.subtract(1, 'seconds'); + assert.equal(a.fromNow(), 'a minute ago', 'Above custom seconds to minute threshold, s < 30'); + // Seconds to minutes threshold moment.relativeTimeThreshold('s', 55); - var a = moment(); + a = moment(); a.subtract(54, 'seconds'); assert.equal(a.fromNow(), 'a few seconds ago', 'Below custom seconds to minutes threshold'); a.subtract(1, 'seconds');