UNPKG

1.37 kBJavaScriptView Raw
1import { getRoundingMethod } from "./_lib/getRoundingMethod.js";
2import { millisecondsInMinute } from "./constants.js";
3import { differenceInMilliseconds } from "./differenceInMilliseconds.js";
4
5/**
6 * The {@link differenceInMinutes} function options.
7 */
8
9/**
10 * @name differenceInMinutes
11 * @category Minute Helpers
12 * @summary Get the number of minutes between the given dates.
13 *
14 * @description
15 * Get the signed number of full (rounded towards 0) minutes between the given dates.
16 *
17 * @param dateLeft - The later date
18 * @param dateRight - The earlier date
19 * @param options - An object with options.
20 *
21 * @returns The number of minutes
22 *
23 * @example
24 * // How many minutes are between 2 July 2014 12:07:59 and 2 July 2014 12:20:00?
25 * const result = differenceInMinutes(
26 * new Date(2014, 6, 2, 12, 20, 0),
27 * new Date(2014, 6, 2, 12, 7, 59)
28 * )
29 * //=> 12
30 *
31 * @example
32 * // How many minutes are between 10:01:59 and 10:00:00
33 * const result = differenceInMinutes(
34 * new Date(2000, 0, 1, 10, 0, 0),
35 * new Date(2000, 0, 1, 10, 1, 59)
36 * )
37 * //=> -1
38 */
39export function differenceInMinutes(dateLeft, dateRight, options) {
40 const diff =
41 differenceInMilliseconds(dateLeft, dateRight) / millisecondsInMinute;
42 return getRoundingMethod(options?.roundingMethod)(diff);
43}
44
45// Fallback for modularized imports:
46export default differenceInMinutes;