getISODay.js 824 B

12345678910111213141516171819202122232425262728293031323334
  1. import { toDate } from "./toDate.js";
  2. /**
  3. * The {@link getISODay} function options.
  4. */
  5. /**
  6. * @name getISODay
  7. * @category Weekday Helpers
  8. * @summary Get the day of the ISO week of the given date.
  9. *
  10. * @description
  11. * Get the day of the ISO week of the given date,
  12. * which is 7 for Sunday, 1 for Monday etc.
  13. *
  14. * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
  15. *
  16. * @param date - The given date
  17. * @param options - An object with options
  18. *
  19. * @returns The day of ISO week
  20. *
  21. * @example
  22. * // Which day of the ISO week is 26 February 2012?
  23. * const result = getISODay(new Date(2012, 1, 26))
  24. * //=> 7
  25. */
  26. export function getISODay(date, options) {
  27. const day = toDate(date, options?.in).getDay();
  28. return day === 0 ? 7 : day;
  29. }
  30. // Fallback for modularized imports:
  31. export default getISODay;