import dayjs , { Dayjs , ConfigType } from "dayjs" ; param usefulFormat param startFromSunday param sizeGuarantee export function calendarTable ( usefulFormat = dayjs ( ) , startFromSunday = false , sizeGuarantee = true ) { const value = dayjs ( usefulFormat ) ; const startOfMonth = value . startOf ( "month" ) ; const endOfMonth = value . endOf ( "month" ) ; const monthStartDay = startOfMonth . date ( ) ; const monthEndDay = endOfMonth . date ( ) ; param element const result = [ ] ; const addDayToResult = ( day ) => { const len = result . length ; if ( len === 0 || result [ len - 1 ] . length >= 7 ) { result . push ( [ day ] ) ; } else { result [ len - 1 ] . push ( day ) ; } } ; if ( startFromSunday ) { const monthStartWeekDay = startOfMonth . day ( ) ; const monthEndWeekDay = endOfMonth . day ( ) ; for ( let i = 0 ; i < monthStartWeekDay ; i ++ ) { addDayToResult ( startOfMonth . subtract ( monthStartWeekDay - i , "day" ) ) ; } for ( let i = monthStartDay ; i <= monthEndDay ; i ++ ) { addDayToResult ( value . date ( i ) ) ; } for ( let i = monthEndWeekDay + 1 ; i <= 6 ; i ++ ) { addDayToResult ( endOfMonth . add ( i - monthEndWeekDay , "day" ) ) ; } } else { const monthStartWeekDay = startOfMonth . day ( ) || 7 ; const monthEndWeekDay = endOfMonth . day ( ) || 7 ; for ( let i = 1 ; i < monthStartWeekDay ; i ++ ) { addDayToResult ( startOfMonth . subtract ( monthStartWeekDay - i , "day" ) ) ; } for ( let i = monthStartDay ; i <= monthEndDay ; i ++ ) { addDayToResult ( value . date ( i ) ) ; } for ( let i = monthEndWeekDay + 1 ; i <= 7 ; i ++ ) { addDayToResult ( endOfMonth . add ( i - monthEndWeekDay , "day" ) ) ; } } if ( result . length < 6 && sizeGuarantee ) { const remain = ( 6 - result . length ) * 7 ; const lastDayOfTable = result [ result . length - 1 ] [ 6 ] ; for ( let i = 1 ; i <= remain ; i ++ ) { addDayToResult ( lastDayOfTable . add ( i , "day" ) ) ; } } return result ; }