Skip to content

A local-first personal finance app

Fix date range calculation in BudgetAnalysisCard (#6875)

tabedzki738a8cda7c19
diff --git a/packages/desktop-client/src/components/reports/reports/BudgetAnalysisCard.tsx b/packages/desktop-client/src/components/reports/reports/BudgetAnalysisCard.tsx
index 791521ba62..2fbfafbaf6 100644
--- a/packages/desktop-client/src/components/reports/reports/BudgetAnalysisCard.tsx
+++ b/packages/desktop-client/src/components/reports/reports/BudgetAnalysisCard.tsx
@@ -16,6 +16,7 @@ import { BudgetAnalysisGraph } from '@desktop-client/components/reports/graphs/B
import { LoadingIndicator } from '@desktop-client/components/reports/LoadingIndicator';
import { ReportCard } from '@desktop-client/components/reports/ReportCard';
import { ReportCardName } from '@desktop-client/components/reports/ReportCardName';
+import { calculateTimeRange } from '@desktop-client/components/reports/reportRanges';
import { createBudgetAnalysisSpreadsheet } from '@desktop-client/components/reports/spreadsheets/budget-analysis-spreadsheet';
import { useReport } from '@desktop-client/components/reports/useReport';
import { useWidgetCopyMenu } from '@desktop-client/components/reports/useWidgetCopyMenu';
@@ -53,15 +54,11 @@ export function BudgetAnalysisCard({
mode: 'sliding-window' as const,
};
- // Calculate date range
- let startDate = timeFrame.start + '-01';
- let endDate = monthUtils.getMonthEnd(timeFrame.end + '-01');
-
- if (timeFrame.mode === 'sliding-window') {
- const currentMonth = monthUtils.currentMonth();
- startDate = monthUtils.subMonths(currentMonth, 5) + '-01';
- endDate = monthUtils.getMonthEnd(currentMonth + '-01');
- }
+ const [startMonth, endMonth] = calculateTimeRange(timeFrame);
+ const startDate = monthUtils.monthFromDate(startMonth) + '-01';
+ const endDate = monthUtils.getMonthEnd(
+ monthUtils.monthFromDate(endMonth) + '-01',
+ );
const getGraphData = useMemo(() => {
return createBudgetAnalysisSpreadsheet({
diff --git a/upcoming-release-notes/6875.md b/upcoming-release-notes/6875.md
new file mode 100644
index 0000000000..ba255b98d0
--- /dev/null
+++ b/upcoming-release-notes/6875.md
@@ -0,0 +1,6 @@
+---
+category: Bugfixes
+authors: [tabedzki]
+---
+
+Budget Analysis Fix: correct date range calculation for card view