"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const normalizeDates = require("./_lib-normalizeDates.cjs");
const compareAsc = require("./compareAsc.cjs");
const differenceInCalendarMonths = require("./differenceInCalendarMonths.cjs");
const isLastDayOfMonth = require("./isLastDayOfMonth.cjs");
function differenceInMonths(laterDate, earlierDate, options) {
  const [laterDate_, workingLaterDate, earlierDate_] = normalizeDates.normalizeDates(
    options?.in,
    laterDate,
    laterDate,
    earlierDate
  );
  const sign = compareAsc.compareAsc(workingLaterDate, earlierDate_);
  const difference = Math.abs(
    differenceInCalendarMonths.differenceInCalendarMonths(workingLaterDate, earlierDate_)
  );
  if (difference < 1) return 0;
  if (workingLaterDate.getMonth() === 1 && workingLaterDate.getDate() > 27)
    workingLaterDate.setDate(30);
  workingLaterDate.setMonth(workingLaterDate.getMonth() - sign * difference);
  let isLastMonthNotFull = compareAsc.compareAsc(workingLaterDate, earlierDate_) === -sign;
  if (isLastDayOfMonth.isLastDayOfMonth(laterDate_) && difference === 1 && compareAsc.compareAsc(laterDate_, earlierDate_) === 1) {
    isLastMonthNotFull = false;
  }
  const result = sign * (difference - +isLastMonthNotFull);
  return result === 0 ? 0 : result;
}
exports.default = differenceInMonths;
exports.differenceInMonths = differenceInMonths;
//# sourceMappingURL=differenceInMonths.cjs.map
