import toDate from '../toDate/index' ; import startOfISOWeek from '../startOfISOWeek/index' ; import requiredArgs from '../_lib/requiredArgs/index' ; name category summary description param { Date | Number } date returns { Number } throws example export default function getISOWeekYear ( dirtyDate ) { requiredArgs ( 1 , arguments ) ; const date = toDate ( dirtyDate ) ; const year = date . getFullYear ( ) ; const fourthOfJanuaryOfNextYear = new Date ( 0 ) ; fourthOfJanuaryOfNextYear . setFullYear ( year + 1 , 0 , 4 ) ; fourthOfJanuaryOfNextYear . setHours ( 0 , 0 , 0 , 0 ) ; const startOfNextYear = startOfISOWeek ( fourthOfJanuaryOfNextYear ) ; const fourthOfJanuaryOfThisYear = new Date ( 0 ) ; fourthOfJanuaryOfThisYear . setFullYear ( year , 0 , 4 ) ; fourthOfJanuaryOfThisYear . setHours ( 0 , 0 , 0 , 0 ) ; const startOfThisYear = startOfISOWeek ( fourthOfJanuaryOfThisYear ) ; if ( date . getTime ( ) >= startOfNextYear . getTime ( ) ) { return year + 1 ; } else if ( date . getTime ( ) >= startOfThisYear . getTime ( ) ) { return year ; } else { return year - 1 ; } }