UNPKG

1.03 kBJavaScriptView Raw
1import { addBusinessDays } from "./addBusinessDays.mjs";
2
3/**
4 * @name subBusinessDays
5 * @category Day Helpers
6 * @summary Substract the specified number of business days (mon - fri) to the given date.
7 *
8 * @description
9 * Substract the specified number of business days (mon - fri) to the given date, ignoring weekends.
10 *
11 * @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).
12 *
13 * @param date - The date to be changed
14 * @param amount - The amount of business days to be subtracted.
15 *
16 * @returns The new date with the business days subtracted
17 *
18 * @example
19 * // Substract 10 business days from 1 September 2014:
20 * const result = subBusinessDays(new Date(2014, 8, 1), 10)
21 * //=> Mon Aug 18 2014 00:00:00 (skipped weekend days)
22 */
23export function subBusinessDays(date, amount) {
24 return addBusinessDays(date, -amount);
25}
26
27// Fallback for modularized imports:
28export default subBusinessDays;