startOfWeekYear.d.ts 2.0 KB

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