isWeekend.js 750 B

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