index.js 715 B

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