index.js 980 B

12345678910111213141516171819202122232425262728293031
  1. import toDate from "../toDate/index.js";
  2. import requiredArgs from "../_lib/requiredArgs/index.js";
  3. /**
  4. * @name endOfSecond
  5. * @category Second Helpers
  6. * @summary Return the end of a second for the given date.
  7. *
  8. * @description
  9. * Return the end of a second for the given date.
  10. * The result will be in the local timezone.
  11. *
  12. * ### v2.0.0 breaking changes:
  13. *
  14. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  15. *
  16. * @param {Date|Number} date - the original date
  17. * @returns {Date} the end of a second
  18. * @throws {TypeError} 1 argument required
  19. *
  20. * @example
  21. * // The end of a second for 1 December 2014 22:15:45.400:
  22. * const result = endOfSecond(new Date(2014, 11, 1, 22, 15, 45, 400))
  23. * //=> Mon Dec 01 2014 22:15:45.999
  24. */
  25. export default function endOfSecond(dirtyDate) {
  26. requiredArgs(1, arguments);
  27. var date = toDate(dirtyDate);
  28. date.setMilliseconds(999);
  29. return date;
  30. }