import toInteger from '../_lib/toInteger/index' ; import toDate from '../toDate/index' ; import startOfISOWeekYear from '../startOfISOWeekYear/index' ; import differenceInCalendarDays from '../differenceInCalendarDays/index' ; import requiredArgs from '../_lib/requiredArgs/index' ; name category summary description param { Date | Number } date param { Number } isoWeekYear returns { Date } throws example export default function setISOWeekYear ( dirtyDate , dirtyISOWeekYear ) { requiredArgs ( 2 , arguments ) ; let date = toDate ( dirtyDate ) ; const isoWeekYear = toInteger ( dirtyISOWeekYear ) ; const diff = differenceInCalendarDays ( date , startOfISOWeekYear ( date ) ) ; const fourthOfJanuary = new Date ( 0 ) ; fourthOfJanuary . setFullYear ( isoWeekYear , 0 , 4 ) ; fourthOfJanuary . setHours ( 0 , 0 , 0 , 0 ) ; date = startOfISOWeekYear ( fourthOfJanuary ) ; date . setDate ( date . getDate ( ) + diff ) ; return date ; }