1 | import { getRoundingMethod } from "./_lib/getRoundingMethod.mjs";
|
2 | import { differenceInMonths } from "./differenceInMonths.mjs";
|
3 |
|
4 | /**
|
5 | * The {@link differenceInQuarters} function options.
|
6 | */
|
7 |
|
8 | /**
|
9 | * @name differenceInQuarters
|
10 | * @category Quarter Helpers
|
11 | * @summary Get the number of quarters between the given dates.
|
12 | *
|
13 | * @description
|
14 | * Get the number of quarters between the given dates.
|
15 | *
|
16 | * @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).
|
17 | *
|
18 | * @param dateLeft - The later date
|
19 | * @param dateRight - The earlier date
|
20 | * @param options - An object with options.
|
21 | *
|
22 | * @returns The number of full quarters
|
23 | *
|
24 | * @example
|
25 | * // How many full quarters are between 31 December 2013 and 2 July 2014?
|
26 | * const result = differenceInQuarters(new Date(2014, 6, 2), new Date(2013, 11, 31))
|
27 | * //=> 2
|
28 | */
|
29 | export function differenceInQuarters(dateLeft, dateRight, options) {
|
30 | const diff = differenceInMonths(dateLeft, dateRight) / 3;
|
31 | return getRoundingMethod(options?.roundingMethod)(diff);
|
32 | }
|
33 |
|
34 | // Fallback for modularized imports:
|
35 | export default differenceInQuarters;
|