setWeekYear.d.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import type {
  2. FirstWeekContainsDateOptions,
  3. LocalizedOptions,
  4. WeekOptions,
  5. } from "./types.js";
  6. /**
  7. * The {@link setWeekYear} function options.
  8. */
  9. export interface SetWeekYearOptions
  10. extends LocalizedOptions<"options">,
  11. WeekOptions,
  12. FirstWeekContainsDateOptions {}
  13. /**
  14. * @name setWeekYear
  15. * @category Week-Numbering Year Helpers
  16. * @summary Set the local week-numbering year to the given date.
  17. *
  18. * @description
  19. * Set the local week-numbering year to the given date,
  20. * saving the week number and the weekday number.
  21. * The exact calculation depends on the values of
  22. * `options.weekStartsOn` (which is the index of the first day of the week)
  23. * and `options.firstWeekContainsDate` (which is the day of January, which is always in
  24. * the first week of the week-numbering year)
  25. *
  26. * Week numbering: https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system
  27. *
  28. * @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).
  29. *
  30. * @param date - The date to be changed
  31. * @param weekYear - The local week-numbering year of the new date
  32. * @param options - An object with options
  33. *
  34. * @returns The new date with the local week-numbering year set
  35. *
  36. * @example
  37. * // Set the local week-numbering year 2004 to 2 January 2010 with default options:
  38. * const result = setWeekYear(new Date(2010, 0, 2), 2004)
  39. * //=> Sat Jan 03 2004 00:00:00
  40. *
  41. * @example
  42. * // Set the local week-numbering year 2004 to 2 January 2010,
  43. * // if Monday is the first day of week
  44. * // and 4 January is always in the first week of the year:
  45. * const result = setWeekYear(new Date(2010, 0, 2), 2004, {
  46. * weekStartsOn: 1,
  47. * firstWeekContainsDate: 4
  48. * })
  49. * //=> Sat Jan 01 2005 00:00:00
  50. */
  51. export declare function setWeekYear<DateType extends Date>(
  52. date: DateType | number | string,
  53. weekYear: number,
  54. options?: SetWeekYearOptions,
  55. ): DateType;