]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Fix test broken only in March 3799/head
authorIskren Chernev <iskren.chernev@gmail.com>
Thu, 2 Mar 2017 08:20:34 +0000 (10:20 +0200)
committerIskren Chernev <iskren.chernev@gmail.com>
Thu, 2 Mar 2017 08:20:34 +0000 (10:20 +0200)
Even if you set custom rounding threshold for days -> month, because relative
time works on durations, which computes it from two moments, if its over
a month in real terms (1st Feb to 2nd March) it will be shown as a month no
matter the thres. It might be considered a bug, but for now it's a feature.

src/test/moment/relative_time.js

index adb9652a13f82258fdb8372dfbb847b24ade3c22..7579e909f6c5d6298902a0e2b17df38d310754f6 100644 (file)
@@ -148,7 +148,7 @@ test('custom rounding', function (assert) {
     moment.relativeTimeThreshold('s', 60);
     moment.relativeTimeThreshold('m', 60);
     moment.relativeTimeThreshold('h', 24);
-    moment.relativeTimeThreshold('d', 31);
+    moment.relativeTimeThreshold('d', 27);
     moment.relativeTimeThreshold('M', 12);
 
     var a = moment.utc();
@@ -160,8 +160,12 @@ test('custom rounding', function (assert) {
     assert.equal(a.toNow(), 'in 23 hours', 'Round down towards the nearest hour');
 
     a = moment.utc();
-    a.subtract({days: 30, hours: 23, minutes: 59});
-    assert.equal(a.toNow(), 'in 30 days', 'Round down towards the nearest day');
+    a.subtract({days: 26, hours: 23, minutes: 59});
+    assert.equal(a.toNow(), 'in 26 days', 'Round down towards the nearest day (just under)');
+
+    a = moment.utc();
+    a.subtract({days: 27});
+    assert.equal(a.toNow(), 'in a month', 'Round down towards the nearest day (just over)');
 
     a = moment.utc();
     a.subtract({days: 364});