From a793de784465220970af617db0660b7b778393fb Mon Sep 17 00:00:00 2001 From: Chad Kruse <314653+chadokruse@users.noreply.github.com> Date: Mon, 25 Nov 2024 20:42:51 -0600 Subject: [PATCH] Inactive algorithm --- shared/algorithms/inactive.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 shared/algorithms/inactive.ts diff --git a/shared/algorithms/inactive.ts b/shared/algorithms/inactive.ts new file mode 100644 index 0000000..ffcd703 --- /dev/null +++ b/shared/algorithms/inactive.ts @@ -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; +};