UNPKG

766 BJavaScriptView Raw
1import { toDate } from "./toDate.mjs";
2
3/**
4 * @name isWeekend
5 * @category Weekday Helpers
6 * @summary Does the given date fall on a weekend?
7 *
8 * @description
9 * Does the given date fall on a weekend?
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 to check
14 *
15 * @returns The date falls on a weekend
16 *
17 * @example
18 * // Does 5 October 2014 fall on a weekend?
19 * const result = isWeekend(new Date(2014, 9, 5))
20 * //=> true
21 */
22export function isWeekend(date) {
23 const day = toDate(date).getDay();
24 return day === 0 || day === 6;
25}
26
27// Fallback for modularized imports:
28export default isWeekend;