From: Iskren Chernev Date: Wed, 13 May 2015 07:27:00 +0000 (-0700) Subject: Add tests for moment#toNow and fixed prototype X-Git-Tag: 2.10.3~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d34425468c8c926ccd1e44d0c1a9288db6c87f67;p=thirdparty%2Fmoment.git Add tests for moment#toNow and fixed prototype --- diff --git a/src/lib/moment/prototype.js b/src/lib/moment/prototype.js index 2e77b6dfc..5601bc0bf 100644 --- a/src/lib/moment/prototype.js +++ b/src/lib/moment/prototype.js @@ -26,7 +26,7 @@ proto.format = format; proto.from = from; proto.fromNow = fromNow; proto.to = to; -proto.toNow = fromNow; +proto.toNow = toNow; proto.get = getSet; proto.invalidAt = invalidAt; proto.isAfter = isAfter; diff --git a/src/test/moment/relative_time.js b/src/test/moment/relative_time.js index 359037b11..0270ab175 100644 --- a/src/test/moment/relative_time.js +++ b/src/test/moment/relative_time.js @@ -3,7 +3,7 @@ import moment from '../../moment'; module('relative time'); -test('default thresholds', function (assert) { +test('default thresholds fromNow', function (assert) { var a = moment(); // Seconds to minutes threshold @@ -41,6 +41,44 @@ test('default thresholds', function (assert) { assert.equal(a.fromNow(), 'a year ago', 'Above default days to years threshold'); }); +test('default thresholds toNow', function (assert) { + var a = moment(); + + // Seconds to minutes threshold + a.subtract(44, 'seconds'); + assert.equal(a.toNow(), 'in a few seconds', 'Below default seconds to minutes threshold'); + a.subtract(1, 'seconds'); + assert.equal(a.toNow(), 'in a minute', 'Above default seconds to minutes threshold'); + + // Minutes to hours threshold + a = moment(); + a.subtract(44, 'minutes'); + assert.equal(a.toNow(), 'in 44 minutes', 'Below default minute to hour threshold'); + a.subtract(1, 'minutes'); + assert.equal(a.toNow(), 'in an hour', 'Above default minute to hour threshold'); + + // Hours to days threshold + a = moment(); + a.subtract(21, 'hours'); + assert.equal(a.toNow(), 'in 21 hours', 'Below default hours to day threshold'); + a.subtract(1, 'hours'); + assert.equal(a.toNow(), 'in a day', 'Above default hours to day threshold'); + + // Days to month threshold + a = moment(); + a.subtract(25, 'days'); + assert.equal(a.toNow(), 'in 25 days', 'Below default days to month (singular) threshold'); + a.subtract(1, 'days'); + assert.equal(a.toNow(), 'in a month', 'Above default days to month (singular) threshold'); + + // months to year threshold + a = moment(); + a.subtract(10, 'months'); + assert.equal(a.toNow(), 'in 10 months', 'Below default days to years threshold'); + a.subtract(1, 'month'); + assert.equal(a.toNow(), 'in a year', 'Above default days to years threshold'); +}); + test('custom thresholds', function (assert) { // Seconds to minutes threshold moment.relativeTimeThreshold('s', 55);