index.js 1000 B

123456789101112131415161718192021222324252627
  1. import toInteger from "../_lib/toInteger/index.js";
  2. import addDays from "../addDays/index.js";
  3. import requiredArgs from "../_lib/requiredArgs/index.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. * @param {Date|Number} date - the date to be changed
  13. * @param {Number} amount - the amount of weeks to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
  14. * @returns {Date} the new date with the weeks added
  15. * @throws {TypeError} 2 arguments required
  16. *
  17. * @example
  18. * // Add 4 weeks to 1 September 2014:
  19. * const result = addWeeks(new Date(2014, 8, 1), 4)
  20. * //=> Mon Sep 29 2014 00:00:00
  21. */
  22. export default function addWeeks(dirtyDate, dirtyAmount) {
  23. requiredArgs(2, arguments);
  24. var amount = toInteger(dirtyAmount);
  25. var days = amount * 7;
  26. return addDays(dirtyDate, days);
  27. }