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