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 = subMonths;
  7. var _index = _interopRequireDefault(require("../_lib/toInteger/index.js"));
  8. var _index2 = _interopRequireDefault(require("../addMonths/index.js"));
  9. var _index3 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
  10. /**
  11. * @name subMonths
  12. * @category Month Helpers
  13. * @summary Subtract the specified number of months from the given date.
  14. *
  15. * @description
  16. * Subtract the specified number of months from the given date.
  17. *
  18. * @param {Date|Number} date - the date to be changed
  19. * @param {Number} amount - the amount of months 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 months subtracted
  21. * @throws {TypeError} 2 arguments required
  22. *
  23. * @example
  24. * // Subtract 5 months from 1 February 2015:
  25. * const result = subMonths(new Date(2015, 1, 1), 5)
  26. * //=> Mon Sep 01 2014 00:00:00
  27. */
  28. function subMonths(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;