From 438d6055c30f0fd5bd550cacdfcbb11316f8c107 Mon Sep 17 00:00:00 2001 From: Michiel ter Reehorst Date: Thu, 3 Jan 2019 13:04:22 +0100 Subject: [PATCH] fix(next): make sure next works with count > 1 --- src/relative-range.js | 8 +++++++- tests/format.spec.js | 16 ++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/relative-range.js b/src/relative-range.js index 33e688a..bf4597b 100644 --- a/src/relative-range.js +++ b/src/relative-range.js @@ -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()) { @@ -186,7 +192,7 @@ class RelativeRange { )[move]( this.cleanMeasure, )[change]( - 1, RANGE_MEASURES.day, + units, measure, ) .endOf(this.cleanMeasure); } else { diff --git a/tests/format.spec.js b/tests/format.spec.js index c511b72..4f90622 100644 --- a/tests/format.spec.js +++ b/tests/format.spec.js @@ -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'), @@ -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', @@ -126,7 +126,7 @@ 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', @@ -134,7 +134,7 @@ describe('RelativeRange#format', function () { es: '1 al 28 de feb.', }, }, { - range: range.next('month'), + range: range.next(1, 'month'), format: 'll', locales: { en: 'Feb 1 - 28, 3000', @@ -146,7 +146,7 @@ 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.', @@ -154,7 +154,7 @@ describe('RelativeRange#format', function () { }, }, { // 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', @@ -162,7 +162,7 @@ describe('RelativeRange#format', function () { }, }, { // 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',