getISODay.js 919 B

123456789101112131415161718192021222324252627282930313233343536
  1. "use strict";
  2. exports.getISODay = getISODay;
  3. var _index = require("./toDate.js");
  4. /**
  5. * @name getISODay
  6. * @category Weekday Helpers
  7. * @summary Get the day of the ISO week of the given date.
  8. *
  9. * @description
  10. * Get the day of the ISO week of the given date,
  11. * which is 7 for Sunday, 1 for Monday etc.
  12. *
  13. * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
  14. *
  15. * @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).
  16. *
  17. * @param date - The given date
  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. function getISODay(date) {
  27. const _date = (0, _index.toDate)(date);
  28. let day = _date.getDay();
  29. if (day === 0) {
  30. day = 7;
  31. }
  32. return day;
  33. }