1 | import { getRoundingMethod } from "./_lib/getRoundingMethod.js";
|
2 | import { differenceInMonths } from "./differenceInMonths.js";
|
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 | * @param laterDate - The later date
|
17 | * @param earlierDate - The earlier date
|
18 | * @param options - An object with options.
|
19 | *
|
20 | * @returns The number of full quarters
|
21 | *
|
22 | * @example
|
23 | * // How many full quarters are between 31 December 2013 and 2 July 2014?
|
24 | * const result = differenceInQuarters(new Date(2014, 6, 2), new Date(2013, 11, 31))
|
25 | * //=> 2
|
26 | */
|
27 | export function differenceInQuarters(laterDate, earlierDate, options) {
|
28 | const diff = differenceInMonths(laterDate, earlierDate, options) / 3;
|
29 | return getRoundingMethod(options?.roundingMethod)(diff);
|
30 | }
|
31 |
|
32 | // Fallback for modularized imports:
|
33 | export default differenceInQuarters;
|