{"ast":null,"code":"import { subDays } from \"./subDays.mjs\";\nimport { subMonths } from \"./subMonths.mjs\";\nimport { constructFrom } from \"./constructFrom.mjs\";\n\n/**\n * @name sub\n * @category Common Helpers\n * @summary Subtract the specified years, months, weeks, days, hours, minutes and seconds from the given date.\n *\n * @description\n * Subtract the specified years, months, weeks, days, hours, minutes and seconds from the given date.\n *\n * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).\n *\n * @param date - The date to be changed\n * @param duration - The object with years, months, weeks, days, hours, minutes and seconds to be subtracted\n *\n * | Key     | Description                        |\n * |---------|------------------------------------|\n * | years   | Amount of years to be subtracted   |\n * | months  | Amount of months to be subtracted  |\n * | weeks   | Amount of weeks to be subtracted   |\n * | days    | Amount of days to be subtracted    |\n * | hours   | Amount of hours to be subtracted   |\n * | minutes | Amount of minutes to be subtracted |\n * | seconds | Amount of seconds to be subtracted |\n *\n * All values default to 0\n *\n * @returns The new date with the seconds subtracted\n *\n * @example\n * // Subtract the following duration from 15 June 2017 15:29:20\n * const result = sub(new Date(2017, 5, 15, 15, 29, 20), {\n *   years: 2,\n *   months: 9,\n *   weeks: 1,\n *   days: 7,\n *   hours: 5,\n *   minutes: 9,\n *   seconds: 30\n * })\n * //=> Mon Sep 1 2014 10:19:50\n */\nexport function sub(date, duration) {\n  const {\n    years = 0,\n    months = 0,\n    weeks = 0,\n    days = 0,\n    hours = 0,\n    minutes = 0,\n    seconds = 0\n  } = duration;\n\n  // Subtract years and months\n  const dateWithoutMonths = subMonths(date, months + years * 12);\n\n  // Subtract weeks and days\n  const dateWithoutDays = subDays(dateWithoutMonths, days + weeks * 7);\n\n  // Subtract hours, minutes and seconds\n  const minutestoSub = minutes + hours * 60;\n  const secondstoSub = seconds + minutestoSub * 60;\n  const mstoSub = secondstoSub * 1000;\n  const finalDate = constructFrom(date, dateWithoutDays.getTime() - mstoSub);\n  return finalDate;\n}\n\n// Fallback for modularized imports:\nexport default sub;","map":null,"metadata":{},"sourceType":"module","externalDependencies":[]}