index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = subSeconds;
  7. var _index = _interopRequireDefault(require("../_lib/toInteger/index.js"));
  8. var _index2 = _interopRequireDefault(require("../addSeconds/index.js"));
  9. var _index3 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
  10. /**
  11. * @name subSeconds
  12. * @category Second Helpers
  13. * @summary Subtract the specified number of seconds from the given date.
  14. *
  15. * @description
  16. * Subtract the specified number of seconds from the given date.
  17. *
  18. * @param {Date|Number} date - the date to be changed
  19. * @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`.
  20. * @returns {Date} the new date with the seconds subtracted
  21. * @throws {TypeError} 2 arguments required
  22. *
  23. * @example
  24. * // Subtract 30 seconds from 10 July 2014 12:45:00:
  25. * const result = subSeconds(new Date(2014, 6, 10, 12, 45, 0), 30)
  26. * //=> Thu Jul 10 2014 12:44:30
  27. */
  28. function subSeconds(dirtyDate, dirtyAmount) {
  29. (0, _index3.default)(2, arguments);
  30. var amount = (0, _index.default)(dirtyAmount);
  31. return (0, _index2.default)(dirtyDate, -amount);
  32. }
  33. module.exports = exports.default;