index.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = subBusinessDays;
  6. var _index = _interopRequireDefault(require("../_lib/toInteger/index.js"));
  7. var _index2 = _interopRequireDefault(require("../addBusinessDays/index.js"));
  8. var _index3 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. /**
  11. * @name subBusinessDays
  12. * @category Day Helpers
  13. * @summary Substract the specified number of business days (mon - fri) to the given date.
  14. *
  15. * @description
  16. * Substract the specified number of business days (mon - fri) to the given date, ignoring weekends.
  17. *
  18. * @param {Date|Number} date - the date to be changed
  19. * @param {Number} amount - the amount of business days 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 business days subtracted
  21. * @throws {TypeError} 2 arguments required
  22. *
  23. * @example
  24. * // Substract 10 business days from 1 September 2014:
  25. * var result = subBusinessDays(new Date(2014, 8, 1), 10)
  26. * //=> Mon Aug 18 2014 00:00:00 (skipped weekend days)
  27. */
  28. function subBusinessDays(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;