fix: allow multi-year income analytics periods
This commit is contained in:
@@ -36,6 +36,17 @@ describe('income period planning', () => {
|
|||||||
).toHaveLength(7);
|
).toHaveLength(7);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('accepts multi-year periods and creates monthly buckets for the entire range', () => {
|
||||||
|
jest.useFakeTimers();
|
||||||
|
jest.setSystemTime(new Date('2026-09-09T12:00:00Z'));
|
||||||
|
|
||||||
|
const plan = planIncomePeriod('2020-01-01', '2025-12-31');
|
||||||
|
expect(plan.selected).toEqual({ from: '2020-01-01', to: '2025-12-31' });
|
||||||
|
expect(plan.granularity).toBe('month');
|
||||||
|
expect(rangeBuckets(plan.selected, plan.granularity)).toHaveLength(72);
|
||||||
|
expect(plan.yearAgo).toEqual({ from: '2019-01-01', to: '2024-12-31' });
|
||||||
|
});
|
||||||
|
|
||||||
it('does not send the unfinished Moscow day as a future instant', () => {
|
it('does not send the unfinished Moscow day as a future instant', () => {
|
||||||
jest.useFakeTimers();
|
jest.useFakeTimers();
|
||||||
jest.setSystemTime(new Date('2026-08-27T21:44:18.510Z'));
|
jest.setSystemTime(new Date('2026-08-27T21:44:18.510Z'));
|
||||||
|
|||||||
@@ -101,8 +101,7 @@ function assertRange(range: DateOnlyRange, today: string): void {
|
|||||||
} catch {
|
} catch {
|
||||||
throw invalidPeriod();
|
throw invalidPeriod();
|
||||||
}
|
}
|
||||||
if (range.from > range.to || range.to > today || rangeDays(range) > 366)
|
if (range.from > range.to || range.to > today) throw invalidPeriod();
|
||||||
throw invalidPeriod();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function dateParts(value: string): [number, number, number] {
|
function dateParts(value: string): [number, number, number] {
|
||||||
|
|||||||
Reference in New Issue
Block a user