import { addWeeks , subWeeks , eachDayOfInterval , startOfMonth , isSameDay , startOfWeek , endOfWeek } from 'date-fns' ; import { DateTuple , WeekStartsOn } from './index.d' ; /**
 * Get all days to display in the mini calendar for a given date.
 */ export const getDaysInMonth = ( currentDate , { weekStartsOn , weeks } ) => { const startOfMonthDate = startOfMonth ( currentDate ) ; const startOfWeekDate = startOfWeek ( startOfMonthDate , { weekStartsOn } ) ; const adjust = isSameDay ( startOfMonthDate , startOfWeekDate ) && weeks === 5 ; const start = adjust ? subWeeks ( startOfWeekDate , 1 ) : startOfWeekDate ; const end = endOfWeek ( addWeeks ( start , weeks ) , { weekStartsOn } ) ; return eachDayOfInterval ( { start , end } ) ; } ; export const getDateTupleFromMonday = ( monday , weekStartsOn ? ) : DateTuple => { const startDateInWeek = startOfWeek ( monday , { weekStartsOn } ) ; const endDateInWeek = endOfWeek ( monday , { weekStartsOn } ) ; return [ startDateInWeek , endDateInWeek ] ; } ;