setSeconds.js 861 B

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. exports.setSeconds = setSeconds;
  3. var _index = require("./toDate.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. * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
  13. *
  14. * @param date - The date to be changed
  15. * @param seconds - The seconds of the new date
  16. *
  17. * @returns The new date with the seconds set
  18. *
  19. * @example
  20. * // Set 45 seconds to 1 September 2014 11:30:40:
  21. * const result = setSeconds(new Date(2014, 8, 1, 11, 30, 40), 45)
  22. * //=> Mon Sep 01 2014 11:30:45
  23. */
  24. function setSeconds(date, seconds) {
  25. const _date = (0, _index.toDate)(date);
  26. _date.setSeconds(seconds);
  27. return _date;
  28. }