/
ai_sampletext
/
DiplomWork
Обзор
Документация
Войти
/
ai_sampletext
/
DiplomWork
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
node_modules/react-day-picker/src/contexts/Navigation/utils/getInitialMonth.ts
22 строки
885 B
boolyshareyo
Initial commit
08 июн 2026, 16:00
08 июн 2026, 16:00
6216a29
Код
Авторство
О чём код?
import { addMonths, differenceInCalendarMonths, startOfMonth } from 'date-fns'; import { DayPickerContextValue } from 'contexts/DayPicker'; /** Return the initial month according to the given options. */ export function getInitialMonth(context: Partial<DayPickerContextValue>): Date { const { month, defaultMonth, today } = context; let initialMonth = month || defaultMonth || today || new Date(); const { toDate, fromDate, numberOfMonths = 1 } = context; // Fix the initialMonth if is after the to-date if (toDate && differenceInCalendarMonths(toDate, initialMonth) < 0) { const offset = -1 * (numberOfMonths - 1); initialMonth = addMonths(toDate, offset); } // Fix the initialMonth if is before the from-date if (fromDate && differenceInCalendarMonths(initialMonth, fromDate) < 0) { initialMonth = fromDate; } return startOfMonth(initialMonth); }