export const getDaysInMonth = ( date ) : number => { const monthIndex = date . getMonth ( ) ; const lastDayOfMonth = new Date ( 0 ) ; lastDayOfMonth . setFullYear ( date . getFullYear ( ) , monthIndex + 1 , 0 ) ; lastDayOfMonth . setHours ( 0 , 0 , 0 , 0 ) ; return lastDayOfMonth . getDate ( ) ; } ; export const addMonths = ( date , value ) : void => { const desiredMonth = date . getMonth ( ) + value ; const dateWithDesiredMonth = new Date ( 0 ) ; dateWithDesiredMonth . setFullYear ( date . getFullYear ( ) , desiredMonth , 1 ) ; dateWithDesiredMonth . setHours ( 0 , 0 , 0 , 0 ) ; const daysInMonth = getDaysInMonth ( dateWithDesiredMonth ) ; date . setMonth ( desiredMonth , Math . min ( daysInMonth , date . getDate ( ) ) ) ; } ;