Build NapCat Artifacts / Windows Loader Test (push) Canceled after 0s
Build NapCat Artifacts / Type Check & Test (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Framework (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Shell (push) Canceled after 0s
24 lines
696 B
Plaintext
24 lines
696 B
Plaintext
import addMonths from "./addMonths.mjs";
|
|
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;
|
|
}
|
|
export {
|
|
monthDiff as m
|
|
};
|