index.js 850 B

12345678910111213141516171819202122232425262728293031
  1. import toDate from "../toDate/index.js";
  2. import requiredArgs from "../_lib/requiredArgs/index.js";
  3. /**
  4. * @name getISODay
  5. * @category Weekday Helpers
  6. * @summary Get the day of the ISO week of the given date.
  7. *
  8. * @description
  9. * Get the day of the ISO week of the given date,
  10. * which is 7 for Sunday, 1 for Monday etc.
  11. *
  12. * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
  13. *
  14. * @param {Date|Number} date - the given date
  15. * @returns {Number} the day of ISO week
  16. * @throws {TypeError} 1 argument required
  17. *
  18. * @example
  19. * // Which day of the ISO week is 26 February 2012?
  20. * const result = getISODay(new Date(2012, 1, 26))
  21. * //=> 7
  22. */
  23. export default function getISODay(dirtyDate) {
  24. requiredArgs(1, arguments);
  25. var date = toDate(dirtyDate);
  26. var day = date.getDay();
  27. if (day === 0) {
  28. day = 7;
  29. }
  30. return day;
  31. }