Skip to content

A local-first personal finance app

[AI] Fix live custom report date ranges (#7889)

Sparklerailb1a105a0ab62
diff --git a/packages/desktop-client/src/components/reports/getLiveRange.test.ts b/packages/desktop-client/src/components/reports/getLiveRange.test.ts
index 476dabb632..bd2f053dc4 100644
--- a/packages/desktop-client/src/components/reports/getLiveRange.test.ts
+++ b/packages/desktop-client/src/components/reports/getLiveRange.test.ts
@@ -35,7 +35,7 @@ describe('getLiveRange', () => {
expect(endExclude).toBe(endInclude);
});
- it('clamps start date to earliestTransaction when data is scarce', () => {
+ it('clamps start date to earliestTransaction when data starts later', () => {
const [start, end] = getLiveRange(
'Last 30 days',
'2016-12-20',
@@ -46,7 +46,7 @@ describe('getLiveRange', () => {
expect(end).toBe('2017-01-01');
});
- it('clamps end date to latestTransaction when it precedes today', () => {
+ it('returns the live range even when latestTransaction precedes today', () => {
const [start, end] = getLiveRange(
'Last 30 days',
EARLIEST,
@@ -54,7 +54,7 @@ describe('getLiveRange', () => {
false,
);
expect(start).toBe('2016-12-03');
- expect(end).toBe('2016-12-25');
+ expect(end).toBe('2017-01-01');
});
it('returns sliding-window mode', () => {
@@ -62,4 +62,18 @@ describe('getLiveRange', () => {
expect(mode).toBe('sliding-window');
});
});
+
+ describe('Year to date', () => {
+ it('ends today even when latestTransaction precedes today', () => {
+ const [start, end] = getLiveRange(
+ 'Year to date',
+ EARLIEST,
+ '2016-12-25',
+ false,
+ );
+
+ expect(start).toBe('2017-01-01');
+ expect(end).toBe('2017-01-01');
+ });
+ });
});
diff --git a/packages/desktop-client/src/components/reports/getLiveRange.ts b/packages/desktop-client/src/components/reports/getLiveRange.ts
index 2794c08e3b..fd3c09336d 100644
--- a/packages/desktop-client/src/components/reports/getLiveRange.ts
+++ b/packages/desktop-client/src/components/reports/getLiveRange.ts
@@ -19,7 +19,6 @@ export function getLiveRange(
case 'yearToDate': {
[dateStart, dateEnd] = validateRange(
earliestTransaction,
- latestTransaction,
monthUtils.getYearStart(monthUtils.currentMonth()) + '-01',
monthUtils.currentDay(),
);
@@ -29,7 +28,6 @@ export function getLiveRange(
const prevMonth = monthUtils.subMonths(monthUtils.currentMonth(), 1);
[dateStart, dateEnd] = validateRange(
earliestTransaction,
- latestTransaction,
monthUtils.firstDayOfMonth(prevMonth),
monthUtils.lastDayOfMonth(prevMonth),
);
@@ -38,7 +36,6 @@ export function getLiveRange(
case 'lastYear': {
[dateStart, dateEnd] = validateRange(
earliestTransaction,
- latestTransaction,
monthUtils.getYearStart(
monthUtils.prevYear(monthUtils.currentMonth()),
) + '-01',
@@ -50,7 +47,6 @@ export function getLiveRange(
case 'priorYearToDate': {
[dateStart, dateEnd] = validateRange(
earliestTransaction,
- latestTransaction,
monthUtils.getYearStart(
monthUtils.prevYear(monthUtils.currentMonth()),
) + '-01',
@@ -61,7 +57,6 @@ export function getLiveRange(
case 'last30Days': {
[dateStart, dateEnd] = validateRange(
earliestTransaction,
- latestTransaction,
monthUtils.subDays(monthUtils.currentDay(), 29),
monthUtils.currentDay(),
);
diff --git a/packages/desktop-client/src/components/reports/reportRanges.ts b/packages/desktop-client/src/components/reports/reportRanges.ts
index 895f192199..6d312f5d9c 100644
--- a/packages/desktop-client/src/components/reports/reportRanges.ts
+++ b/packages/desktop-client/src/components/reports/reportRanges.ts
@@ -88,16 +88,13 @@ export function validateEnd(
export function validateRange(
earliest: string,
- latest: string,
start: string,
end: string,
-) {
- if (end > latest) {
- end = latest;
- }
+): [string, string] {
if (start < earliest) {
start = earliest;
}
+
return [start, end];
}
diff --git a/packages/desktop-client/src/components/reports/reports/GetCardData.tsx b/packages/desktop-client/src/components/reports/reports/GetCardData.tsx
index ff7b19f5d1..3281072148 100644
--- a/packages/desktop-client/src/components/reports/reports/GetCardData.tsx
+++ b/packages/desktop-client/src/components/reports/reports/GetCardData.tsx
@@ -98,7 +98,7 @@ export function GetCardData({
firstDayOfWeekIdx,
);
startDate = dateStart || report.startDate;
- endDate = dateEnd || report.startDate;
+ endDate = dateEnd || report.endDate;
}
const fromDate = convertFromDate(report.interval);
diff --git a/upcoming-release-notes/7889.md b/upcoming-release-notes/7889.md
new file mode 100644
index 0000000000..9d1c62beb4
--- /dev/null
+++ b/upcoming-release-notes/7889.md
@@ -0,0 +1,6 @@
+---
+category: Bugfixes
+authors: [Haldoctor]
+---
+
+Fix live custom report date ranges when opening filtered transactions.