Skip to content

Commit

Permalink
fix(next): make sure next works with count > 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Michiel ter Reehorst committed Jan 3, 2019
1 parent a735375 commit 438d605
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
8 changes: 7 additions & 1 deletion src/relative-range.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,21 @@ class RelativeRange {

let change;
let move;
let units;
let measure;

switch (this.type) {
case RANGE_TYPES.next:
change = 'add';
move = 'endOf';
units = this.units;
measure = this.countableMeasure;
break;
default:
change = 'subtract';
move = 'startOf';
units = 1;
measure = RANGE_MEASURES.day;
}

if (this.isWhole()) {
Expand All @@ -186,7 +192,7 @@ class RelativeRange {
)[move](
this.cleanMeasure,
)[change](
1, RANGE_MEASURES.day,
units, measure,
)
.endOf(this.cleanMeasure);
} else {
Expand Down
16 changes: 8 additions & 8 deletions tests/format.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ describe('RelativeRange#format', function () {
nl: '01-01-2998 t/m 31-12-2999',
},
}, {
range: range.next('month'),
range: range.next(2, 'month'),
format: 'L',
locales: {
nl: '01-02-3000 t/m 28-02-3000',
nl: '01-02-3000 t/m 31-03-3000',
},
}, {
range: range.previous(1, 'month'),
Expand All @@ -77,7 +77,7 @@ describe('RelativeRange#format', function () {
en: 'January 1, 2998 - December 31, 2999',
},
}, {
range: range.next('month'),
range: range.next(1, 'month'),
format: 'LL',
locales: {
nl: '1 t/m 28 februari',
Expand Down Expand Up @@ -126,15 +126,15 @@ describe('RelativeRange#format', function () {
es: '31 de dic. de 2999',
},
}, {
range: range.next('month'),
range: range.next(1, 'month'),
format: 'll',
locales: {
en: 'Feb 1 - 28',
nl: '1 t/m 28 feb.',
es: '1 al 28 de feb.',
},
}, {
range: range.next('month'),
range: range.next(1, 'month'),
format: 'll',
locales: {
en: 'Feb 1 - 28, 3000',
Expand All @@ -146,23 +146,23 @@ describe('RelativeRange#format', function () {
},
}, {
// This is local
range: range.next('month').locale('nl'),
range: range.next(1, 'month').locale('nl'),
format: 'll',
locales: {
en: '1 t/m 28 feb.',
nl: '1 t/m 28 feb.',
},
}, {
// This is a locale being changed
range: range.next('month').locale('nl').locale('en'),
range: range.next(1, 'month').locale('nl').locale('en'),
format: 'll',
locales: {
en: 'Feb 1 - 28',
nl: 'Feb 1 - 28',
},
}, {
// This is a locale being unset
range: range.next('month').locale('es').locale(false),
range: range.next(1, 'month').locale('es').locale(false),
format: 'll',
locales: {
en: 'Feb 1 - 28',
Expand Down

0 comments on commit 438d605

Please sign in to comment.