index.js 1013 B

1234567891011121314151617181920212223242526
  1. import toInteger from "../_lib/toInteger/index.js";
  2. import addYears from "../addYears/index.js";
  3. import requiredArgs from "../_lib/requiredArgs/index.js";
  4. /**
  5. * @name subYears
  6. * @category Year Helpers
  7. * @summary Subtract the specified number of years from the given date.
  8. *
  9. * @description
  10. * Subtract the specified number of years from the given date.
  11. *
  12. * @param {Date|Number} date - the date to be changed
  13. * @param {Number} amount - the amount of years to be subtracted. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
  14. * @returns {Date} the new date with the years subtracted
  15. * @throws {TypeError} 2 arguments required
  16. *
  17. * @example
  18. * // Subtract 5 years from 1 September 2014:
  19. * const result = subYears(new Date(2014, 8, 1), 5)
  20. * //=> Tue Sep 01 2009 00:00:00
  21. */
  22. export default function subYears(dirtyDate, dirtyAmount) {
  23. requiredArgs(2, arguments);
  24. var amount = toInteger(dirtyAmount);
  25. return addYears(dirtyDate, -amount);
  26. }