UNPKG

964 BJavaScriptView Raw
1import { toDate } from "./toDate.mjs";
2
3/**
4 * @name isAfter
5 * @category Common Helpers
6 * @summary Is the first date after the second one?
7 *
8 * @description
9 * Is the first date after the second one?
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 date - The date that should be after the other one to return true
14 * @param dateToCompare - The date to compare with
15 *
16 * @returns The first date is after the second date
17 *
18 * @example
19 * // Is 10 July 1989 after 11 February 1987?
20 * const result = isAfter(new Date(1989, 6, 10), new Date(1987, 1, 11))
21 * //=> true
22 */
23export function isAfter(date, dateToCompare) {
24 const _date = toDate(date);
25 const _dateToCompare = toDate(dateToCompare);
26 return _date.getTime() > _dateToCompare.getTime();
27}
28
29// Fallback for modularized imports:
30export default isAfter;