UNPKG

750 BJavaScriptView Raw
1"use strict";
2exports.isWeekend = isWeekend;
3var _index = require("./toDate.js");
4
5/**
6 * @name isWeekend
7 * @category Weekday Helpers
8 * @summary Does the given date fall on a weekend?
9 *
10 * @description
11 * Does the given date fall on a weekend?
12 *
13 * @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).
14 *
15 * @param date - The date to check
16 *
17 * @returns The date falls on a weekend
18 *
19 * @example
20 * // Does 5 October 2014 fall on a weekend?
21 * const result = isWeekend(new Date(2014, 9, 5))
22 * //=> true
23 */
24function isWeekend(date) {
25 const day = (0, _index.toDate)(date).getDay();
26 return day === 0 || day === 6;
27}