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:
1 parent
54a51752ac
commit
65d83ddec7
1 file changed
+16
-5
+16
-5
@@ -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 {
|
||||
const fixed = isDynamic(view) ? "1M" : view;
|
||||
const aligned = periodOf(range.start, fixed);
|
||||
if (aligned.start === range.start && aligned.end === range.end) {
|
||||
const anchor = dir === 1 ? addDays(range.end, 1) : addDays(range.start, -1);
|
||||
return periodOf(anchor, fixed);
|
||||
const unit = unitOf(range, view);
|
||||
if (unit) {
|
||||
const anchor = dir === 1 ? periodOf(range.start, unit).end : range.start;
|
||||
return periodOf(addDays(anchor, dir), unit);
|
||||
}
|
||||
const days = daysBetween(range.start, range.end) + 1;
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user