addWeeks.js 845 B

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. exports.addWeeks = addWeeks;
  3. var _index = require("./addDays.js");
  4. /**
  5. * @name addWeeks
  6. * @category Week Helpers
  7. * @summary Add the specified number of weeks to the given date.
  8. *
  9. * @description
  10. * Add the specified number of week to the given date.
  11. *
  12. * @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).
  13. *
  14. * @param date - The date to be changed
  15. * @param amount - The amount of weeks to be added.
  16. *
  17. * @returns The new date with the weeks added
  18. *
  19. * @example
  20. * // Add 4 weeks to 1 September 2014:
  21. * const result = addWeeks(new Date(2014, 8, 1), 4)
  22. * //=> Mon Sep 29 2014 00:00:00
  23. */
  24. function addWeeks(date, amount) {
  25. const days = amount * 7;
  26. return (0, _index.addDays)(date, days);
  27. }