1 | import { normalizeDates } from "./_lib/normalizeDates.js";
|
2 | import { startOfHour } from "./startOfHour.js";
|
3 |
|
4 | /**
|
5 | * The {@link isSameHour} function options.
|
6 | */
|
7 |
|
8 | /**
|
9 | * @name isSameHour
|
10 | * @category Hour Helpers
|
11 | * @summary Are the given dates in the same hour (and same day)?
|
12 | *
|
13 | * @description
|
14 | * Are the given dates in the same hour (and same day)?
|
15 | *
|
16 | * @param dateLeft - The first date to check
|
17 | * @param dateRight - The second date to check
|
18 | * @param options - An object with options
|
19 | *
|
20 | * @returns The dates are in the same hour (and same day)
|
21 | *
|
22 | * @example
|
23 | * // Are 4 September 2014 06:00:00 and 4 September 06:30:00 in the same hour?
|
24 | * const result = isSameHour(new Date(2014, 8, 4, 6, 0), new Date(2014, 8, 4, 6, 30))
|
25 | * //=> true
|
26 | *
|
27 | * @example
|
28 | * // Are 4 September 2014 06:00:00 and 5 September 06:00:00 in the same hour?
|
29 | * const result = isSameHour(new Date(2014, 8, 4, 6, 0), new Date(2014, 8, 5, 6, 0))
|
30 | * //=> false
|
31 | */
|
32 | export function isSameHour(dateLeft, dateRight, options) {
|
33 | const [dateLeft_, dateRight_] = normalizeDates(
|
34 | options?.in,
|
35 | dateLeft,
|
36 | dateRight,
|
37 | );
|
38 | return +startOfHour(dateLeft_) === +startOfHour(dateRight_);
|
39 | }
|
40 |
|
41 | // Fallback for modularized imports:
|
42 | export default isSameHour;
|