UNPKG

2.03 kBSource Map (JSON)View Raw
1{"version":3,"file":"get-week-number.js","sourceRoot":"","sources":["../../../src/calendar/helpers/get-week-number.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,SAAS,iBAAiB,CAAC,cAA8B,EAAE,IAAU;IACnE,MAAM,EAAE,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;IACjC,MAAM,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAC7B,MAAM,CAAC,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;IAC5B,MAAM,EAAE,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;IAE5B,IAAI,MAAM,GAAG,EAAE,CAAC;IAEhB,IAAI,cAAc,KAAK,kBAAkB;QAAE,MAAM,GAAG,CAAC,CAAC;IACtD,IAAI,cAAc,KAAK,mBAAmB;QAAE,MAAM,GAAG,CAAC,CAAC;IACvD,IAAI,cAAc,KAAK,iBAAiB;QAAE,MAAM,GAAG,CAAC,CAAC;IAErD,OAAO,SAAS,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,CAAC;AAC3C,CAAC;AAKD,MAAM,UAAU,aAAa,CAAC,cAA8B,EAAE,IAAU;IACtE,MAAM,cAAc,GAAG,iBAAiB,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;IAC/D,MAAM,cAAc,GAAG,SAAS,CAAC,cAAc,CAAC,cAAc,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACxE,MAAM,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,cAAc,GAAG,CAAC,cAAc,CAAC,GAAG,KAAK,CAAC,CAAC;IAElE,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;AAChC,CAAC","sourcesContent":["import type { WeekNumberType } from '../calendar_typing.js';\nimport { toUTCDate } from './to-utc-date.js';\n\nfunction getNormalizedDate(weekNumberType: WeekNumberType, date: Date): Date {\n const fy = date.getUTCFullYear();\n const m = date.getUTCMonth();\n const d = date.getUTCDate();\n const wd = date.getUTCDay();\n\n let offset = wd;\n\n if (weekNumberType === 'first-4-day-week') offset = 3;\n if (weekNumberType === 'first-day-of-year') offset = 6;\n if (weekNumberType === 'first-full-week') offset = 0;\n\n return toUTCDate(fy, m, d - wd + offset);\n}\n\n/**\n * {@link https://bit.ly/2UvEN2y Compute week number by type}\n */\nexport function getWeekNumber(weekNumberType: WeekNumberType, date: Date): number {\n const normalizedDate = getNormalizedDate(weekNumberType, date);\n const firstDayOfYear = toUTCDate(normalizedDate.getUTCFullYear(), 0, 1);\n const numDays = 1 + ((+normalizedDate - +firstDayOfYear) / 864e5);\n\n return Math.ceil(numDays / 7);\n}\n"]}
\No newline at end of file