From 79dacba6d607e2869d40c2ca54266280ae95a738 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sun, 31 Jan 2021 21:38:35 +0800 Subject: [PATCH] fix shifting date range bug when date range crosses one year --- src/lib/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/utils.js b/src/lib/utils.js index 44c42e49..c7290512 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -156,7 +156,7 @@ function getShiftedDateRange(minTime, maxTime, scale) { const lastDayOfMonth = maxDateTime.clone().endOf('month'); if (firstDayOfMonth.unix() === minDateTime.unix() && lastDayOfMonth.unix() === maxDateTime.unix()) { - const months = getMonth(maxDateTime) - getMonth(minDateTime) + 1; + const months = getYear(maxDateTime) * 12 + getMonth(maxDateTime) - getYear(minDateTime) * 12 - getMonth(minDateTime) + 1; const newMinDateTime = minDateTime.add(months * scale, 'months'); const newMaxDateTime = newMinDateTime.clone().add(months, 'months').subtract(1, 'seconds');