From 9fcc0ec01068372e6756f60bb49d83643e07466d Mon Sep 17 00:00:00 2001 From: Sergey Krylov Date: Wed, 9 Sep 2026 11:10:11 +0300 Subject: [PATCH] fix: allow multi-year income analytics periods --- src/tbank/income-period.spec.ts | 11 +++++++++++ src/tbank/income-period.ts | 3 +-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/tbank/income-period.spec.ts b/src/tbank/income-period.spec.ts index bc15d38..9c995c2 100644 --- a/src/tbank/income-period.spec.ts +++ b/src/tbank/income-period.spec.ts @@ -36,6 +36,17 @@ describe('income period planning', () => { ).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', () => { jest.useFakeTimers(); jest.setSystemTime(new Date('2026-08-27T21:44:18.510Z')); diff --git a/src/tbank/income-period.ts b/src/tbank/income-period.ts index 59a06f0..96bce67 100644 --- a/src/tbank/income-period.ts +++ b/src/tbank/income-period.ts @@ -101,8 +101,7 @@ function assertRange(range: DateOnlyRange, today: string): void { } catch { throw invalidPeriod(); } - if (range.from > range.to || range.to > today || rangeDays(range) > 366) - throw invalidPeriod(); + if (range.from > range.to || range.to > today) throw invalidPeriod(); } function dateParts(value: string): [number, number, number] {