startOfSecond.js 891 B

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. exports.startOfSecond = startOfSecond;
  3. var _index = require("./toDate.js");
  4. /**
  5. * @name startOfSecond
  6. * @category Second Helpers
  7. * @summary Return the start of a second for the given date.
  8. *
  9. * @description
  10. * Return the start of a second for the given date.
  11. * The result will be in the local timezone.
  12. *
  13. * @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).
  14. *
  15. * @param date - The original date
  16. *
  17. * @returns The start of a second
  18. *
  19. * @example
  20. * // The start of a second for 1 December 2014 22:15:45.400:
  21. * const result = startOfSecond(new Date(2014, 11, 1, 22, 15, 45, 400))
  22. * //=> Mon Dec 01 2014 22:15:45.000
  23. */
  24. function startOfSecond(date) {
  25. const _date = (0, _index.toDate)(date);
  26. _date.setMilliseconds(0);
  27. return _date;
  28. }