index.js 897 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 setMinutes
  6. * @category Minute Helpers
  7. * @summary Set the minutes to the given date.
  8. *
  9. * @description
  10. * Set the minutes to the given date.
  11. *
  12. * @param {Date|Number} date - the date to be changed
  13. * @param {Number} minutes - the minutes of the new date
  14. * @returns {Date} the new date with the minutes set
  15. * @throws {TypeError} 2 arguments required
  16. *
  17. * @example
  18. * // Set 45 minutes to 1 September 2014 11:30:40:
  19. * const result = setMinutes(new Date(2014, 8, 1, 11, 30, 40), 45)
  20. * //=> Mon Sep 01 2014 11:45:40
  21. */
  22. export default function setMinutes(dirtyDate, dirtyMinutes) {
  23. requiredArgs(2, arguments);
  24. var date = toDate(dirtyDate);
  25. var minutes = toInteger(dirtyMinutes);
  26. date.setMinutes(minutes);
  27. return date;
  28. }