/
ai_sampletext
/
DiplomWork
Обзор
Документация
Войти
/
ai_sampletext
/
DiplomWork
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
node_modules/react-day-picker/src/components/Table/utils/getMonthWeeks.ts
55 строк
1 KB
boolyshareyo
Initial commit
08 июн 2026, 16:00
08 июн 2026, 16:00
6216a29
Код
Авторство
О чём код?
import { addWeeks, endOfMonth, getWeeksInMonth, Locale, startOfMonth } from 'date-fns'; import { daysToMonthWeeks } from './daysToMonthWeeks'; /** Represents a week in the month.*/ export type MonthWeek = { /** The week number from the start of the year. */ weekNumber: number; /** The dates in the week. */ dates: Date[]; }; /** * Return the weeks belonging to the given month, adding the "outside days" to * the first and last week. */ export function getMonthWeeks( month: Date, options: { locale: Locale; useFixedWeeks?: boolean; weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6; firstWeekContainsDate?: 1 | 4; ISOWeek?: boolean; } ): MonthWeek[] { const weeksInMonth: MonthWeek[] = daysToMonthWeeks( startOfMonth(month), endOfMonth(month), options ); if (options?.useFixedWeeks) { // Add extra weeks to the month, up to 6 weeks const nrOfMonthWeeks = getWeeksInMonth(month, options); if (nrOfMonthWeeks < 6) { const lastWeek = weeksInMonth[weeksInMonth.length - 1]; const lastDate = lastWeek.dates[lastWeek.dates.length - 1]; const toDate = addWeeks(lastDate, 6 - nrOfMonthWeeks); const extraWeeks = daysToMonthWeeks( addWeeks(lastDate, 1), toDate, options ); weeksInMonth.push(...extraWeeks); } } return weeksInMonth; }