subDays.js 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. import { addDays } from "./addDays.js";
  2. /**
  3. * The {@link subDays} function options.
  4. */
  5. /**
  6. * @name subDays
  7. * @category Day Helpers
  8. * @summary Subtract the specified number of days from the given date.
  9. *
  10. * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
  11. * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
  12. *
  13. * @param date - The date to be changed
  14. * @param amount - The amount of days to be subtracted.
  15. * @param options - An object with options
  16. *
  17. * @returns The new date with the days subtracted
  18. *
  19. * @example
  20. * // Subtract 10 days from 1 September 2014:
  21. * const result = subDays(new Date(2014, 8, 1), 10)
  22. * //=> Fri Aug 22 2014 00:00:00
  23. */
  24. export function subDays(date, amount, options) {
  25. return addDays(date, -amount, options);
  26. }
  27. // Fallback for modularized imports:
  28. export default subDays;