fix(period): [ and ] after month or year to date step by whole months or years

Month to date went back to 13-30 Sept because a partial range was moved
by its length; a range that starts a month, quarter, half or year now
steps by that unit.
This commit is contained in:
hh committed 2026-10-18 17:26:58 +00:00
1 parent 54a51752ac
commit 65d83ddec7
1 file changed
+16 -5
+16 -5
View File
@@ -118,12 +118,23 @@ export function periodOf(value: string, view: ViewRange): Range {
} }
} }
const UNITS: ViewRange[] = ["1M", "3M", "6M", "1Y"];
function unitOf(range: Range, view: ViewRange): ViewRange | null {
const units = isDynamic(view) ? UNITS : [view, ...UNITS];
return (
units.find((unit) => {
const aligned = periodOf(range.start, unit);
return aligned.start === range.start && range.end <= aligned.end;
}) ?? null
);
}
export function shiftPeriod(range: Range, view: ViewRange, dir: 1 | -1): Range { export function shiftPeriod(range: Range, view: ViewRange, dir: 1 | -1): Range {
const fixed = isDynamic(view) ? "1M" : view; const unit = unitOf(range, view);
const aligned = periodOf(range.start, fixed); if (unit) {
if (aligned.start === range.start && aligned.end === range.end) { const anchor = dir === 1 ? periodOf(range.start, unit).end : range.start;
const anchor = dir === 1 ? addDays(range.end, 1) : addDays(range.start, -1); return periodOf(addDays(anchor, dir), unit);
return periodOf(anchor, fixed);
} }
const days = daysBetween(range.start, range.end) + 1; const days = daysBetween(range.start, range.end) + 1;
return { return {