index.js 726 B

123456789101112131415161718192021222324
  1. var addMonths = require('../add_months/index.js')
  2. /**
  3. * @category Month Helpers
  4. * @summary Subtract the specified number of months from the given date.
  5. *
  6. * @description
  7. * Subtract the specified number of months from the given date.
  8. *
  9. * @param {Date|String|Number} date - the date to be changed
  10. * @param {Number} amount - the amount of months to be subtracted
  11. * @returns {Date} the new date with the months subtracted
  12. *
  13. * @example
  14. * // Subtract 5 months from 1 February 2015:
  15. * var result = subMonths(new Date(2015, 1, 1), 5)
  16. * //=> Mon Sep 01 2014 00:00:00
  17. */
  18. function subMonths (dirtyDate, dirtyAmount) {
  19. var amount = Number(dirtyAmount)
  20. return addMonths(dirtyDate, -amount)
  21. }
  22. module.exports = subMonths