35 lines
1.2 KiB
JavaScript
35 lines
1.2 KiB
JavaScript
|
"use strict";
|
||
|
exports.differenceInQuarters = differenceInQuarters;
|
||
|
var _index = require("./_lib/getRoundingMethod.js");
|
||
|
var _index2 = require("./differenceInMonths.js");
|
||
|
|
||
|
/**
|
||
|
* The {@link differenceInQuarters} function options.
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* @name differenceInQuarters
|
||
|
* @category Quarter Helpers
|
||
|
* @summary Get the number of quarters between the given dates.
|
||
|
*
|
||
|
* @description
|
||
|
* Get the number of quarters between the given dates.
|
||
|
*
|
||
|
* @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).
|
||
|
*
|
||
|
* @param dateLeft - The later date
|
||
|
* @param dateRight - The earlier date
|
||
|
* @param options - An object with options.
|
||
|
*
|
||
|
* @returns The number of full quarters
|
||
|
*
|
||
|
* @example
|
||
|
* // How many full quarters are between 31 December 2013 and 2 July 2014?
|
||
|
* const result = differenceInQuarters(new Date(2014, 6, 2), new Date(2013, 11, 31))
|
||
|
* //=> 2
|
||
|
*/
|
||
|
function differenceInQuarters(dateLeft, dateRight, options) {
|
||
|
const diff = (0, _index2.differenceInMonths)(dateLeft, dateRight) / 3;
|
||
|
return (0, _index.getRoundingMethod)(options?.roundingMethod)(diff);
|
||
|
}
|