subBusinessDays.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { addBusinessDays } from "./addBusinessDays.js";
  2. /**
  3. * The {@link subBusinessDays} function options.
  4. */
  5. /**
  6. * @name subBusinessDays
  7. * @category Day Helpers
  8. * @summary Subtract the specified number of business days (mon - fri) from the given date.
  9. *
  10. * @description
  11. * Subtract the specified number of business days (mon - fri) from the given date, ignoring weekends.
  12. *
  13. * @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).
  14. * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
  15. *
  16. * @param date - The date to be changed
  17. * @param amount - The amount of business days to be subtracted.
  18. * @param options - An object with options
  19. *
  20. * @returns The new date with the business days subtracted
  21. *
  22. * @example
  23. * // Subtract 10 business days from 1 September 2014:
  24. * const result = subBusinessDays(new Date(2014, 8, 1), 10)
  25. * //=> Mon Aug 18 2014 00:00:00 (skipped weekend days)
  26. */
  27. export function subBusinessDays(date, amount, options) {
  28. return addBusinessDays(date, -amount, options);
  29. }
  30. // Fallback for modularized imports:
  31. export default subBusinessDays;