UNPKG

935 BJavaScriptView Raw
1import { toDate } from "./toDate.mjs";
2
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 * @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).
15 *
16 * @param date - The given date
17 *
18 * @returns The day of ISO week
19 *
20 * @example
21 * // Which day of the ISO week is 26 February 2012?
22 * const result = getISODay(new Date(2012, 1, 26))
23 * //=> 7
24 */
25export function getISODay(date) {
26 const _date = toDate(date);
27 let day = _date.getDay();
28
29 if (day === 0) {
30 day = 7;
31 }
32
33 return day;
34}
35
36// Fallback for modularized imports:
37export default getISODay;