UNPKG

1.13 kBJavaScriptView Raw
1import { constructFrom } from "./constructFrom.js";
2import { constructNow } from "./constructNow.js";
3import { isSameWeek } from "./isSameWeek.js";
4
5/**
6 * The {@link isThisWeek} function options.
7 */
8
9/**
10 * @name isThisWeek
11 * @category Week Helpers
12 * @summary Is the given date in the same week as the current date?
13 * @pure false
14 *
15 * @description
16 * Is the given date in the same week as the current date?
17 *
18 * @param date - The date to check
19 * @param options - The object with options
20 *
21 * @returns The date is in this week
22 *
23 * @example
24 * // If today is 25 September 2014, is 21 September 2014 in this week?
25 * const result = isThisWeek(new Date(2014, 8, 21))
26 * //=> true
27 *
28 * @example
29 * // If today is 25 September 2014 and week starts with Monday
30 * // is 21 September 2014 in this week?
31 * const result = isThisWeek(new Date(2014, 8, 21), { weekStartsOn: 1 })
32 * //=> false
33 */
34export function isThisWeek(date, options) {
35 return isSameWeek(
36 constructFrom(options?.in || date, date),
37 constructNow(options?.in || date),
38 options,
39 );
40}
41
42// Fallback for modularized imports:
43export default isThisWeek;