( date: DateArg<DateType>, weekYear: number, options?: SetISOWeekYearOptions<ResultDate> | undefined, )
| 37 | * //=> Mon Jan 01 2007 00:00:00 |
| 38 | */ |
| 39 | export function setISOWeekYear< |
| 40 | DateType extends Date, |
| 41 | ResultDate extends Date = DateType, |
| 42 | >( |
| 43 | date: DateArg<DateType>, |
| 44 | weekYear: number, |
| 45 | options?: SetISOWeekYearOptions<ResultDate> | undefined, |
| 46 | ): ResultDate { |
| 47 | let _date = toDate(date, options?.in); |
| 48 | const diff = differenceInCalendarDays( |
| 49 | _date, |
| 50 | startOfISOWeekYear(_date, options), |
| 51 | ); |
| 52 | const fourthOfJanuary = constructFrom(options?.in || date, 0); |
| 53 | fourthOfJanuary.setFullYear(weekYear, 0, 4); |
| 54 | fourthOfJanuary.setHours(0, 0, 0, 0); |
| 55 | _date = startOfISOWeekYear(fourthOfJanuary); |
| 56 | _date.setDate(_date.getDate() + diff); |
| 57 | return _date; |
| 58 | } |
no test coverage detected