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;
});
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');