keep the day of the month when shifting the date range forward or backward if the selected date range is a full month

This commit is contained in:
MaysWind
2024-11-05 00:55:22 +08:00
parent 1c906113ab
commit c3a880e5f5
+13
View File
@@ -355,6 +355,7 @@ export function getShiftedDateRange(minTime, maxTime, scale) {
const firstDayOfMonth = minDateTime.clone().startOf('month');
const lastDayOfMonth = maxDateTime.clone().endOf('month');
// check whether the date range matches full months
if (firstDayOfMonth.unix() === minDateTime.unix() && lastDayOfMonth.unix() === maxDateTime.unix()) {
const months = getYear(maxDateTime) * 12 + getMonth(maxDateTime) - getYear(minDateTime) * 12 - getMonth(minDateTime) + 1;
const newMinDateTime = minDateTime.add(months * scale, 'months');
@@ -366,6 +367,18 @@ export function getShiftedDateRange(minTime, maxTime, scale) {
};
}
// 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()) {
const newMinDateTime = minDateTime.add(1 * scale, 'months');
const newMaxDateTime = maxDateTime.add(1 * scale, 'months');
return {
minTime: newMinDateTime.unix(),
maxTime: newMaxDateTime.unix()
};
}
const range = (maxTime - minTime + 1) * scale;
return {