index.js 691 B

123456789101112131415161718192021222324
  1. var addMonths = require('../add_months/index.js')
  2. /**
  3. * @category Year Helpers
  4. * @summary Add the specified number of years to the given date.
  5. *
  6. * @description
  7. * Add the specified number of years to 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 added
  11. * @returns {Date} the new date with the years added
  12. *
  13. * @example
  14. * // Add 5 years to 1 September 2014:
  15. * var result = addYears(new Date(2014, 8, 1), 5)
  16. * //=> Sun Sep 01 2019 00:00:00
  17. */
  18. function addYears (dirtyDate, dirtyAmount) {
  19. var amount = Number(dirtyAmount)
  20. return addMonths(dirtyDate, amount * 12)
  21. }
  22. module.exports = addYears