"use strict"; const addMonths = require("./addMonths.js"); function monthDiff(a, b) { const aTime = +a; const bTime = +b; if (aTime < bTime) { return -monthDiff(b, a); } const wholeMonthDiff = (b.getFullYear() - a.getFullYear()) * 12 + (b.getMonth() - a.getMonth()); const anchor = +addMonths(new Date(aTime), wholeMonthDiff); let anchor2; let adjust; if (bTime < anchor) { anchor2 = +addMonths(new Date(aTime), wholeMonthDiff - 1); adjust = (bTime - anchor) / (anchor - anchor2); } else { anchor2 = +addMonths(new Date(aTime), wholeMonthDiff + 1); adjust = (bTime - anchor) / (anchor2 - anchor); } return -(wholeMonthDiff + adjust) || 0; } exports.monthDiff = monthDiff;