function getBenefitReduction(dob, retireDate) {
const birthYearDate = dayjs(dob);
const retireYearDate = dayjs(retireDate);
const floatYearsAfter62yo = retireYearDate.diff(birthYearDate,'years',true)-62
const intYearsAfter62yo = retireYearDate.diff(birthYearDate,'years',false)-62
let reduction;
const rowOfReduction = benefitReductionTable.find(d => d.year === birthYearDate.year());
if (rowOfReduction) {
let extraMonthsCredit = 0
if ((floatYearsAfter62yo - intYearsAfter62yo) !== 0) {
const fractionOfYearMonths = (floatYearsAfter62yo - intYearsAfter62yo);
extraMonthsCredit = (rowOfReduction.PctCreditForEachDelayYear*0.01) * fractionOfYearMonths;
}
return rowOfReduction.yearsFrom62[intYearsAfter62yo] + extraMonthsCredit;
} else {
throw new Error("No reduction found – try experimental table");
}
}