UNPKG

940 BJavaScriptView Raw
1import { toDate } from "./toDate.mjs";
2
3/**
4 * @name isEqual
5 * @category Common Helpers
6 * @summary Are the given dates equal?
7 *
8 * @description
9 * Are the given dates equal?
10 *
11 * @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).
12 *
13 * @param dateLeft - The first date to compare
14 * @param dateRight - The second date to compare
15 *
16 * @returns The dates are equal
17 *
18 * @example
19 * // Are 2 July 2014 06:30:45.000 and 2 July 2014 06:30:45.500 equal?
20 * const result = isEqual(
21 * new Date(2014, 6, 2, 6, 30, 45, 0),
22 * new Date(2014, 6, 2, 6, 30, 45, 500)
23 * )
24 * //=> false
25 */
26export function isEqual(leftDate, rightDate) {
27 const _dateLeft = toDate(leftDate);
28 const _dateRight = toDate(rightDate);
29 return +_dateLeft === +_dateRight;
30}
31
32// Fallback for modularized imports:
33export default isEqual;