Skip to content

Commit

Permalink
Inactive algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
chadokruse committed Nov 26, 2024
1 parent d644a9a commit a793de7
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions shared/algorithms/inactive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
interface Config {
monthsThreshold: number;
}

const config: Config = {
monthsThreshold: 36,
};

const calculateMonthsBetween = (fyeDate: number, currentDate: Date): number => {
const fyeYear = Math.floor(fyeDate / 100);
const fyeMonth = fyeDate % 100;

if (fyeDate < 100000 || fyeDate > 999999 || fyeMonth < 1 || fyeMonth > 12) {
throw new Error('fyeDate is expected to be in IRS tax period format YYYYMM');
}

const currentYear = currentDate.getFullYear();
const currentMonth = currentDate.getMonth() + 1;

return (currentYear - fyeYear) * 12 + (currentMonth - fyeMonth);
};

export const isLikelyInactive = (eobmfStatus: boolean, taxPeriod: number): boolean => {
const monthsSinceFye = calculateMonthsBetween(taxPeriod, new Date());
if (eobmfStatus === false) {
if (monthsSinceFye >= config.monthsThreshold) {
return true;
}
}
return false;
};

0 comments on commit a793de7

Please sign in to comment.