UNPKG

1.69 kBTypeScriptView Raw
1/**
2 * @name differenceInBusinessDays
3 * @category Day Helpers
4 * @summary Get the number of business days between the given dates.
5 *
6 * @description
7 * Get the number of business day periods between the given dates.
8 * Business days being days that arent in the weekend.
9 * Like `differenceInCalendarDays`, the function removes the times from
10 * the dates before calculating the difference.
11 *
12 * @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).
13 *
14 * @param dateLeft - The later date
15 * @param dateRight - The earlier date
16 *
17 * @returns The number of business days
18 *
19 * @example
20 * // How many business days are between
21 * // 10 January 2014 and 20 July 2014?
22 * const result = differenceInBusinessDays(
23 * new Date(2014, 6, 20),
24 * new Date(2014, 0, 10)
25 * )
26 * //=> 136
27 *
28 * // How many business days are between
29 * // 30 November 2021 and 1 November 2021?
30 * const result = differenceInBusinessDays(
31 * new Date(2021, 10, 30),
32 * new Date(2021, 10, 1)
33 * )
34 * //=> 21
35 *
36 * // How many business days are between
37 * // 1 November 2021 and 1 December 2021?
38 * const result = differenceInBusinessDays(
39 * new Date(2021, 10, 1),
40 * new Date(2021, 11, 1)
41 * )
42 * //=> -22
43 *
44 * // How many business days are between
45 * // 1 November 2021 and 1 November 2021 ?
46 * const result = differenceInBusinessDays(
47 * new Date(2021, 10, 1),
48 * new Date(2021, 10, 1)
49 * )
50 * //=> 0
51 */
52export declare function differenceInBusinessDays<DateType extends Date>(
53 dateLeft: DateType | number | string,
54 dateRight: DateType | number | string,
55): number;