MCPcopy
hub / github.com/date-fns/date-fns / setISOWeekYear

Function setISOWeekYear

pkgs/core/src/setISOWeekYear/index.ts:39–58  ·  view source on GitHub ↗
(
  date: DateArg<DateType>,
  weekYear: number,
  options?: SetISOWeekYearOptions<ResultDate> | undefined,
)

Source from the content-addressed store, hash-verified

37 * //=> Mon Jan 01 2007 00:00:00
38 */
39export 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}

Callers 2

test.tsFile · 0.90
addISOWeekYearsFunction · 0.90

Calls 4

toDateFunction · 0.90
differenceInCalendarDaysFunction · 0.90
startOfISOWeekYearFunction · 0.90
constructFromFunction · 0.90

Tested by

no test coverage detected