import { normalizeInterval } from "./_lib-normalizeInterval.js";
import { add } from "./add.js";
import { differenceInDays } from "./differenceInDays.js";
import { differenceInHours } from "./differenceInHours.js";
import { differenceInMinutes } from "./differenceInMinutes.js";
import { differenceInMonths } from "./differenceInMonths.js";
import { differenceInSeconds } from "./differenceInSeconds.js";
import { differenceInYears } from "./differenceInYears.js";
function intervalToDuration(interval, options) {
  const { start, end } = normalizeInterval(options?.in, interval);
  const duration = {};
  const years = differenceInYears(end, start);
  if (years) duration.years = years;
  const remainingMonths = add(start, { years: duration.years });
  const months = differenceInMonths(end, remainingMonths);
  if (months) duration.months = months;
  const remainingDays = add(remainingMonths, { months: duration.months });
  const days = differenceInDays(end, remainingDays);
  if (days) duration.days = days;
  const remainingHours = add(remainingDays, { days: duration.days });
  const hours = differenceInHours(end, remainingHours);
  if (hours) duration.hours = hours;
  const remainingMinutes = add(remainingHours, { hours: duration.hours });
  const minutes = differenceInMinutes(end, remainingMinutes);
  if (minutes) duration.minutes = minutes;
  const remainingSeconds = add(remainingMinutes, { minutes: duration.minutes });
  const seconds = differenceInSeconds(end, remainingSeconds);
  if (seconds) duration.seconds = seconds;
  return duration;
}
export {
  intervalToDuration as default,
  intervalToDuration
};
//# sourceMappingURL=intervalToDuration.js.map
