UNPKG

750 BJavaScriptView Raw
1import { toDate } from "./toDate.js";
2
3/**
4 * The {@link isWeekend} function options.
5 */
6
7/**
8 * @name isWeekend
9 * @category Weekday Helpers
10 * @summary Does the given date fall on a weekend?
11 *
12 * @description
13 * Does the given date fall on a weekend? A weekend is either Saturday (`6`) or Sunday (`0`).
14 *
15 * @param date - The date to check
16 * @param options - An object with options
17 *
18 * @returns The date falls on a weekend
19 *
20 * @example
21 * // Does 5 October 2014 fall on a weekend?
22 * const result = isWeekend(new Date(2014, 9, 5))
23 * //=> true
24 */
25export function isWeekend(date, options) {
26 const day = toDate(date, options?.in).getDay();
27 return day === 0 || day === 6;
28}
29
30// Fallback for modularized imports:
31export default isWeekend;