From c748c89d77bc2c474c4977152f83009e8e4f7d39 Mon Sep 17 00:00:00 2001 From: shall0pass <20625555+shall0pass@users.noreply.github.com> Date: Thu, 16 Nov 2023 13:42:14 -0600 Subject: [PATCH 1/2] logic --- .../src/server/budget/goals/goalsSchedule.ts | 13 +++++++++++++ packages/loot-core/src/shared/months.ts | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/packages/loot-core/src/server/budget/goals/goalsSchedule.ts b/packages/loot-core/src/server/budget/goals/goalsSchedule.ts index f75bd7506ee..cc4d1ae38ee 100644 --- a/packages/loot-core/src/server/budget/goals/goalsSchedule.ts +++ b/packages/loot-core/src/server/budget/goals/goalsSchedule.ts @@ -74,11 +74,24 @@ export async function goalsSchedule( ); while (next_date < next_month) { monthlyTarget += -target; + let current_date = next_date; next_date = monthUtils.addDays(next_date, 1); next_date = getNextDate( dateConditions, monthUtils._parse(next_date), ); + let diffDays = monthUtils.differenceInCalendarDays( + next_date, + current_date, + ); + if (!diffDays) { + next_date = monthUtils.addDays(next_date, 3); + next_date = getNextDate( + dateConditions, + monthUtils._parse(next_date), + ); + } + console.log(diffDays); } t[ll].target = -monthlyTarget; totalScheduledGoal += target; diff --git a/packages/loot-core/src/shared/months.ts b/packages/loot-core/src/shared/months.ts index 4ea22213595..651333707f9 100644 --- a/packages/loot-core/src/shared/months.ts +++ b/packages/loot-core/src/shared/months.ts @@ -137,6 +137,13 @@ export function differenceInCalendarMonths( return d.differenceInCalendarMonths(_parse(month1), _parse(month2)); } +export function differenceInCalendarDays( + month1: DateLike, + month2: DateLike, +): number { + return d.differenceInCalendarDays(_parse(month1), _parse(month2)); +} + export function subMonths(month: string | Date, n: number) { return d.format(d.subMonths(_parse(month), n), 'yyyy-MM'); } From b7a56333ac87ce01de1ac19a04240107a5ca5497 Mon Sep 17 00:00:00 2001 From: shall0pass <20625555+shall0pass@users.noreply.github.com> Date: Thu, 16 Nov 2023 13:51:19 -0600 Subject: [PATCH 2/2] release note --- packages/loot-core/src/server/budget/goals/goalsSchedule.ts | 1 - upcoming-release-notes/1917.md | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 upcoming-release-notes/1917.md diff --git a/packages/loot-core/src/server/budget/goals/goalsSchedule.ts b/packages/loot-core/src/server/budget/goals/goalsSchedule.ts index cc4d1ae38ee..b11e5835395 100644 --- a/packages/loot-core/src/server/budget/goals/goalsSchedule.ts +++ b/packages/loot-core/src/server/budget/goals/goalsSchedule.ts @@ -91,7 +91,6 @@ export async function goalsSchedule( monthUtils._parse(next_date), ); } - console.log(diffDays); } t[ll].target = -monthlyTarget; totalScheduledGoal += target; diff --git a/upcoming-release-notes/1917.md b/upcoming-release-notes/1917.md new file mode 100644 index 00000000000..a61ec5f59b9 --- /dev/null +++ b/upcoming-release-notes/1917.md @@ -0,0 +1,6 @@ +--- +category: Bugfix +authors: [shall0pass] +--- + +Goals: Fix infinite loop situation with Schedule keyword