subWeeks.mjs 874 B

12345678910111213141516171819202122232425262728
  1. import { addWeeks } from "./addWeeks.mjs";
  2. /**
  3. * @name subWeeks
  4. * @category Week Helpers
  5. * @summary Subtract the specified number of weeks from the given date.
  6. *
  7. * @description
  8. * Subtract the specified number of weeks from the given date.
  9. *
  10. * @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).
  11. *
  12. * @param date - The date to be changed
  13. * @param amount - The amount of weeks to be subtracted.
  14. *
  15. * @returns The new date with the weeks subtracted
  16. *
  17. * @example
  18. * // Subtract 4 weeks from 1 September 2014:
  19. * const result = subWeeks(new Date(2014, 8, 1), 4)
  20. * //=> Mon Aug 04 2014 00:00:00
  21. */
  22. export function subWeeks(date, amount) {
  23. return addWeeks(date, -amount);
  24. }
  25. // Fallback for modularized imports:
  26. export default subWeeks;