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