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:
@@ -355,6 +355,7 @@ export function getShiftedDateRange(minTime, maxTime, scale) {
|
|||||||
const firstDayOfMonth = minDateTime.clone().startOf('month');
|
const firstDayOfMonth = minDateTime.clone().startOf('month');
|
||||||
const lastDayOfMonth = maxDateTime.clone().endOf('month');
|
const lastDayOfMonth = maxDateTime.clone().endOf('month');
|
||||||
|
|
||||||
|
// check whether the date range matches full months
|
||||||
if (firstDayOfMonth.unix() === minDateTime.unix() && lastDayOfMonth.unix() === maxDateTime.unix()) {
|
if (firstDayOfMonth.unix() === minDateTime.unix() && lastDayOfMonth.unix() === maxDateTime.unix()) {
|
||||||
const months = getYear(maxDateTime) * 12 + getMonth(maxDateTime) - getYear(minDateTime) * 12 - getMonth(minDateTime) + 1;
|
const months = getYear(maxDateTime) * 12 + getMonth(maxDateTime) - getYear(minDateTime) * 12 - getMonth(minDateTime) + 1;
|
||||||
const newMinDateTime = minDateTime.add(months * scale, 'months');
|
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;
|
const range = (maxTime - minTime + 1) * scale;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user