isWeekend.mjs 766 B

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