{"ast":null,"code":"import { constructFrom } from \"./constructFrom.mjs\";\nimport { differenceInCalendarDays } from \"./differenceInCalendarDays.mjs\";\nimport { startOfWeekYear } from \"./startOfWeekYear.mjs\";\nimport { toDate } from \"./toDate.mjs\";\nimport { getDefaultOptions } from \"./_lib/defaultOptions.mjs\";\n\n/**\n * The {@link setWeekYear} function options.\n */\n\n/**\n * @name setWeekYear\n * @category Week-Numbering Year Helpers\n * @summary Set the local week-numbering year to the given date.\n *\n * @description\n * Set the local week-numbering year to the given date,\n * saving the week number and the weekday number.\n * The exact calculation depends on the values of\n * `options.weekStartsOn` (which is the index of the first day of the week)\n * and `options.firstWeekContainsDate` (which is the day of January, which is always in\n * the first week of the week-numbering year)\n *\n * Week numbering: https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system\n *\n * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).\n *\n * @param date - The date to be changed\n * @param weekYear - The local week-numbering year of the new date\n * @param options - An object with options\n *\n * @returns The new date with the local week-numbering year set\n *\n * @example\n * // Set the local week-numbering year 2004 to 2 January 2010 with default options:\n * const result = setWeekYear(new Date(2010, 0, 2), 2004)\n * //=> Sat Jan 03 2004 00:00:00\n *\n * @example\n * // Set the local week-numbering year 2004 to 2 January 2010,\n * // if Monday is the first day of week\n * // and 4 January is always in the first week of the year:\n * const result = setWeekYear(new Date(2010, 0, 2), 2004, {\n *   weekStartsOn: 1,\n *   firstWeekContainsDate: 4\n * })\n * //=> Sat Jan 01 2005 00:00:00\n */\nexport function setWeekYear(date, weekYear, options) {\n  const defaultOptions = getDefaultOptions();\n  const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions.firstWeekContainsDate ?? defaultOptions.locale?.options?.firstWeekContainsDate ?? 1;\n  let _date = toDate(date);\n  const diff = differenceInCalendarDays(_date, startOfWeekYear(_date, options));\n  const firstWeek = constructFrom(date, 0);\n  firstWeek.setFullYear(weekYear, 0, firstWeekContainsDate);\n  firstWeek.setHours(0, 0, 0, 0);\n  _date = startOfWeekYear(firstWeek, options);\n  _date.setDate(_date.getDate() + diff);\n  return _date;\n}\n\n// Fallback for modularized imports:\nexport default setWeekYear;","map":null,"metadata":{},"sourceType":"module","externalDependencies":[]}