1 | import { getRoundingMethod } from "./_lib/getRoundingMethod.mjs";
|
2 | import { millisecondsInMinute } from "./constants.mjs";
|
3 | import { differenceInMilliseconds } from "./differenceInMilliseconds.mjs";
|
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 | * @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).
|
18 | *
|
19 | * @param dateLeft - The later date
|
20 | * @param dateRight - The earlier date
|
21 | * @param options - An object with options.
|
22 | *
|
23 | * @returns The number of minutes
|
24 | *
|
25 | * @example
|
26 | * // How many minutes are between 2 July 2014 12:07:59 and 2 July 2014 12:20:00?
|
27 | * const result = differenceInMinutes(
|
28 | * new Date(2014, 6, 2, 12, 20, 0),
|
29 | * new Date(2014, 6, 2, 12, 7, 59)
|
30 | * )
|
31 | * //=> 12
|
32 | *
|
33 | * @example
|
34 | * // How many minutes are between 10:01:59 and 10:00:00
|
35 | * const result = differenceInMinutes(
|
36 | * new Date(2000, 0, 1, 10, 0, 0),
|
37 | * new Date(2000, 0, 1, 10, 1, 59)
|
38 | * )
|
39 | * //=> -1
|
40 | */
|
41 | export function differenceInMinutes(dateLeft, dateRight, options) {
|
42 | const diff =
|
43 | differenceInMilliseconds(dateLeft, dateRight) / millisecondsInMinute;
|
44 | return getRoundingMethod(options?.roundingMethod)(diff);
|
45 | }
|
46 |
|
47 | // Fallback for modularized imports:
|
48 | export default differenceInMinutes;
|