Skip to content

Commit

Permalink
[feature] Fix #4518: Add support to add/subtract ISO weeks (#4563)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashsearle authored and marwahaha committed Dec 13, 2018
1 parent 3147fbc commit 155ce4b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/duration/constructor.js
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions src/test/moment/add_subtract.js
Expand Up @@ -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');
});

0 comments on commit 155ce4b

Please sign in to comment.