Skip to content

Commit

Permalink
logic
Browse files Browse the repository at this point in the history
  • Loading branch information
shall0pass committed Nov 16, 2023
1 parent 7c0b7a2 commit c748c89
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/loot-core/src/server/budget/goals/goalsSchedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions packages/loot-core/src/shared/months.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down

0 comments on commit c748c89

Please sign in to comment.