getISODay.mjs 935 B

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