From 601a1f83c69d19c396b4740bb100e7ef356acc75 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sun, 24 Aug 2025 00:23:49 +0800 Subject: [PATCH] fix the date range may be incorrect when switching between fiscal years --- src/lib/datetime.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lib/datetime.ts b/src/lib/datetime.ts index 22034e23..82a9ef42 100644 --- a/src/lib/datetime.ts +++ b/src/lib/datetime.ts @@ -653,6 +653,18 @@ export function getShiftedDateRange(minTime: number, maxTime: number, scale: num }; } + // check whether the date range matches one full year + if (minDateTime.clone().add(1, 'years').subtract(1, 'seconds').unix() === maxDateTime.unix() || + maxDateTime.clone().subtract(1, 'years').add(1, 'seconds').unix() === minDateTime.unix()) { + const newMinDateTime = minDateTime.add(1 * scale, 'years'); + const newMaxDateTime = maxDateTime.add(1 * scale, 'years'); + + return { + minTime: newMinDateTime.unix(), + maxTime: newMaxDateTime.unix() + }; + } + // check whether the date range matches one full month if (minDateTime.clone().add(1, 'months').subtract(1, 'seconds').unix() === maxDateTime.unix() || maxDateTime.clone().subtract(1, 'months').add(1, 'seconds').unix() === minDateTime.unix()) {