getWeek.d.mts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import type {
  2. FirstWeekContainsDateOptions,
  3. LocalizedOptions,
  4. WeekOptions,
  5. } from "./types.js";
  6. /**
  7. * The {@link getWeek} function options.
  8. */
  9. export interface GetWeekOptions
  10. extends LocalizedOptions<"options">,
  11. WeekOptions,
  12. FirstWeekContainsDateOptions {}
  13. /**
  14. * @name getWeek
  15. * @category Week Helpers
  16. * @summary Get the local week index of the given date.
  17. *
  18. * @description
  19. * Get the local week index of the given date.
  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 given date
  30. * @param options - An object with options
  31. *
  32. * @returns The week
  33. *
  34. * @example
  35. * // Which week of the local week numbering year is 2 January 2005 with default options?
  36. * const result = getWeek(new Date(2005, 0, 2))
  37. * //=> 2
  38. *
  39. * @example
  40. * // Which week of the local week numbering year is 2 January 2005,
  41. * // if Monday is the first day of the week,
  42. * // and the first week of the year always contains 4 January?
  43. * const result = getWeek(new Date(2005, 0, 2), {
  44. * weekStartsOn: 1,
  45. * firstWeekContainsDate: 4
  46. * })
  47. * //=> 53
  48. */
  49. export declare function getWeek<DateType extends Date>(
  50. date: DateType | number | string,
  51. options?: GetWeekOptions,
  52. ): number;