index.js 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. import toInteger from "../_lib/toInteger/index.js";
  2. import addSeconds from "../addSeconds/index.js";
  3. import requiredArgs from "../_lib/requiredArgs/index.js";
  4. /**
  5. * @name subSeconds
  6. * @category Second Helpers
  7. * @summary Subtract the specified number of seconds from the given date.
  8. *
  9. * @description
  10. * Subtract the specified number of seconds from the given date.
  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 date to be changed
  17. * @param {Number} amount - the amount of seconds to be subtracted. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
  18. * @returns {Date} the new date with the seconds subtracted
  19. * @throws {TypeError} 2 arguments required
  20. *
  21. * @example
  22. * // Subtract 30 seconds from 10 July 2014 12:45:00:
  23. * const result = subSeconds(new Date(2014, 6, 10, 12, 45, 0), 30)
  24. * //=> Thu Jul 10 2014 12:44:30
  25. */
  26. export default function subSeconds(dirtyDate, dirtyAmount) {
  27. requiredArgs(2, arguments);
  28. var amount = toInteger(dirtyAmount);
  29. return addSeconds(dirtyDate, -amount);
  30. }