startOfWeekYear.d.ts 1.8 KB

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