index.js 927 B

12345678910111213141516171819202122232425262728
  1. import toInteger from "../_lib/toInteger/index.js";
  2. import toDate from "../toDate/index.js";
  3. import requiredArgs from "../_lib/requiredArgs/index.js";
  4. /**
  5. * @name setDate
  6. * @category Day Helpers
  7. * @summary Set the day of the month to the given date.
  8. *
  9. * @description
  10. * Set the day of the month to the given date.
  11. *
  12. * @param {Date|Number} date - the date to be changed
  13. * @param {Number} dayOfMonth - the day of the month of the new date
  14. * @returns {Date} the new date with the day of the month set
  15. * @throws {TypeError} 2 arguments required
  16. *
  17. * @example
  18. * // Set the 30th day of the month to 1 September 2014:
  19. * const result = setDate(new Date(2014, 8, 1), 30)
  20. * //=> Tue Sep 30 2014 00:00:00
  21. */
  22. export default function setDate(dirtyDate, dirtyDayOfMonth) {
  23. requiredArgs(2, arguments);
  24. var date = toDate(dirtyDate);
  25. var dayOfMonth = toInteger(dirtyDayOfMonth);
  26. date.setDate(dayOfMonth);
  27. return date;
  28. }