index.js 884 B

123456789101112131415161718192021222324252627282930
  1. import toDate from "../toDate/index.js";
  2. import requiredArgs from "../_lib/requiredArgs/index.js";
  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. * ### v2.0.0 breaking changes:
  12. *
  13. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  14. *
  15. * @param {Date|Number} date - the date to check
  16. * @returns {Boolean} the date falls on a weekend
  17. * @throws {TypeError} 1 argument required
  18. *
  19. * @example
  20. * // Does 5 October 2014 fall on a weekend?
  21. * const result = isWeekend(new Date(2014, 9, 5))
  22. * //=> true
  23. */
  24. export default function isWeekend(dirtyDate) {
  25. requiredArgs(1, arguments);
  26. var date = toDate(dirtyDate);
  27. var day = date.getDay();
  28. return day === 0 || day === 6;
  29. }