import differenceInCalendarDays from '../differenceInCalendarDays/index' ; import startOfWeekYear from '../startOfWeekYear/index' ; import toDate from '../toDate/index' ; import toInteger from '../_lib/toInteger/index' ; import requiredArgs from '../_lib/requiredArgs/index' ; import type { LocaleOptions , WeekStartOptions , FirstWeekContainsDateOptions , } from '../types' ; name category summary description param { Date | Number } date param { Number } weekYear param options param { Locale } options . locale - the locale object. See [Locale] https param { 0 | 1 | 2 | 3 | 4 | 5 | 6 } options . weekStartsOn param { 1 | 2 | 3 | 4 | 5 | 6 | 7 } options . firstWeekContainsDate returns { Date } throws throws throws example example export default function setWeekYear ( dirtyDate , dirtyWeekYear , options = { } ) { requiredArgs ( 2 , arguments ) ; const locale = options . locale ; const localeFirstWeekContainsDate = locale && locale . options && locale . options . firstWeekContainsDate ; const defaultFirstWeekContainsDate = localeFirstWeekContainsDate == null ? 1 : toInteger ( localeFirstWeekContainsDate ) ; const firstWeekContainsDate = options . firstWeekContainsDate == null ? defaultFirstWeekContainsDate : toInteger ( options . firstWeekContainsDate ) ; let date = toDate ( dirtyDate ) ; const weekYear = toInteger ( dirtyWeekYear ) ; const diff = differenceInCalendarDays ( date , startOfWeekYear ( date , options ) ) ; const firstWeek = new Date ( 0 ) ; firstWeek . setFullYear ( weekYear , 0 , firstWeekContainsDate ) ; firstWeek . setHours ( 0 , 0 , 0 , 0 ) ; date = startOfWeekYear ( firstWeek , options ) ; date . setDate ( date . getDate ( ) + diff ) ; return date ; }