UNPKG

821 BJavaScriptView Raw
1import { constructFrom } from "./constructFrom.js";
2import { constructNow } from "./constructNow.js";
3import { isSameDay } from "./isSameDay.js";
4
5/**
6 * The {@link isToday} function options.
7 */
8
9/**
10 * @name isToday
11 * @category Day Helpers
12 * @summary Is the given date today?
13 * @pure false
14 *
15 * @description
16 * Is the given date today?
17 *
18 * @param date - The date to check
19 * @param options - An object with options
20 *
21 * @returns The date is today
22 *
23 * @example
24 * // If today is 6 October 2014, is 6 October 14:00:00 today?
25 * const result = isToday(new Date(2014, 9, 6, 14, 0))
26 * //=> true
27 */
28export function isToday(date, options) {
29 return isSameDay(
30 constructFrom(options?.in || date, date),
31 constructNow(options?.in || date),
32 );
33}
34
35// Fallback for modularized imports:
36export default isToday;