]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
[feature] Fix #4518: Add support to add/subtract ISO weeks (#4563)
authorAsh <ash@hexmen.com>
Thu, 13 Dec 2018 05:12:16 +0000 (05:12 +0000)
committerKunal Marwaha <marwahaha@berkeley.edu>
Thu, 13 Dec 2018 05:12:16 +0000 (21:12 -0800)
src/lib/duration/constructor.js
src/test/moment/add_subtract.js

index 2d86d5e2c009473454eb172b0080d114ca9ec02a..894ba1dc67bb995c5fce47c26400ef806ccc362e 100644 (file)
@@ -7,7 +7,7 @@ export function Duration (duration) {
         years = normalizedInput.year || 0,
         quarters = normalizedInput.quarter || 0,
         months = normalizedInput.month || 0,
-        weeks = normalizedInput.week || 0,
+        weeks = normalizedInput.week || normalizedInput.isoWeek || 0,
         days = normalizedInput.day || 0,
         hours = normalizedInput.hour || 0,
         minutes = normalizedInput.minute || 0,
index 6b1e6259579e04761463d4cf38d2bb3c759d752f..3f21298cd61bcc74f8c5be6050ba323d680cd1ea 100644 (file)
@@ -368,3 +368,13 @@ test('add decimal values of days and months', function (assert) {
     assert.equal(moment([2016, 0,1]).add(1.6, 'years').format('YYYY-MM-DD'), '2017-08-01', 'add 1.6 years becomes 1.6*12 = 19.2, round, 19 months');
     assert.equal(moment([2016,0,1]).add(1.1, 'quarters').format('YYYY-MM-DD'), '2016-04-01', 'add 1.1 quarters 1.1*3=3.3, round, 3 months');
 });
+
+test('add/subtract ISO week', function (assert) {
+    assert.equal(moment([2016,3,15]).subtract(1, 'W').date(), 8, 'subtract 1 iso week short');
+    assert.equal(moment([2016,3,15]).subtract(1, 'isoweek').date(), 8, 'subtract 1 iso week long singular');
+    assert.equal(moment([2016,3,15]).subtract(1, 'isoweeks').date(), 8, 'subtract 1 iso weeks long');
+
+    assert.equal(moment([2016,3,15]).add(1, 'W').date(), 22, 'add 1 iso week short');
+    assert.equal(moment([2016,3,15]).add(1, 'isoweek').date(), 22, 'add 1 week long singular');
+    assert.equal(moment([2016,3,15]).add(1, 'isoweeks').date(), 22, 'add 1 weeks long');
+});