import toInteger from '../_lib/toInteger/index' ; import toDate from '../toDate/index' ; import getDaysInMonth from '../getDaysInMonth/index' ; import requiredArgs from '../_lib/requiredArgs/index' ; name category summary description param { Date | Number } date param { Number } month returns { Date } throws example export default function setMonth ( dirtyDate , dirtyMonth ) { requiredArgs ( 2 , arguments ) ; const date = toDate ( dirtyDate ) ; const month = toInteger ( dirtyMonth ) ; const year = date . getFullYear ( ) ; const day = date . getDate ( ) ; const dateWithDesiredMonth = new Date ( 0 ) ; dateWithDesiredMonth . setFullYear ( year , month , 15 ) ; dateWithDesiredMonth . setHours ( 0 , 0 , 0 , 0 ) ; const daysInMonth = getDaysInMonth ( dateWithDesiredMonth ) ; date . setMonth ( month , Math . min ( day , daysInMonth ) ) ; return date ; }