From b1e5821453fd58d01f3233a0236be14a4e70f04f Mon Sep 17 00:00:00 2001 From: vansh2408 Date: Mon, 27 Oct 2025 22:01:51 +0530 Subject: [PATCH] Include first and last date of each calendar year in getChartDateMap() --- .../calculator/portfolio-calculator.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts b/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts index 10e5c15cb..3f9af1569 100644 --- a/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts +++ b/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts @@ -889,6 +889,23 @@ export abstract class PortfolioCalculator { } } + const startYear = startDate.getFullYear(); + const endYear = endDate.getFullYear(); + + for (let year = startYear; year <= endYear; year++) { + const firstDay = new Date(year, 0, 1); // January 1st + const lastDay = new Date(year, 11, 31); // December 31st + + // Add only if they lie within the selected range + if (!isBefore(firstDay, startDate) && !isAfter(firstDay, endDate)) { + chartDateMap[format(firstDay, DATE_FORMAT)] = true; + } + + if (!isBefore(lastDay, startDate) && !isAfter(lastDay, endDate)) { + chartDateMap[format(lastDay, DATE_FORMAT)] = true; + } + } + return chartDateMap; }