]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
[bugfix] end of months diff bugs
authorAhmed Elsenousi <asenousy@gmail.com>
Wed, 25 Jul 2018 17:06:21 +0000 (18:06 +0100)
committerIskren Chernev <iskren.chernev@gmail.com>
Wed, 29 Apr 2020 15:36:43 +0000 (18:36 +0300)
src/test/moment/diff.js

index cf8c4a2f5fb0611bbf94d1b3521b1339dae6737c..47ad599d232e506c7c2e80014e22ec2b8496455d 100644 (file)
@@ -209,6 +209,16 @@ test('diff month', function (assert) {
     );
 });
 
+test('end of month diff', function (assert) {
+    assert.equal(moment([2016, 1, 29]).diff([2016, 0, 30], 'months'), 1, 'Feb 29 to Jan 30 should be 1 month');
+    assert.equal(moment([2016, 1, 29]).diff([2016, 0, 31], 'months'), 1, 'Feb 30 to Jan 31 should be 1 month');
+    assert.equal(moment([2016, 4, 31]).add(1,'month').diff(moment([2016, 4, 31]), 'month'), 1, '(May 31 plus 1 month) to May 31 should be 1 month diff');
+});
+
+test('end of month diff with time behind', function (assert) {
+    assert.equal(moment([2017, 2, 31, 1]).diff([2017, 1, 28, 2], 'months'), 1, 'Feb 28 to March 31 should be 1 month');
+});
+
 test('diff across DST', function (assert) {
     var dst = dstForYear(2012),
         a,