startOfWeek.d.cts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import type {
  2. ContextOptions,
  3. DateArg,
  4. LocalizedOptions,
  5. WeekOptions,
  6. } from "./types.js";
  7. /**
  8. * The {@link startOfWeek} function options.
  9. */
  10. export interface StartOfWeekOptions<DateType extends Date = Date>
  11. extends LocalizedOptions<"options">,
  12. WeekOptions,
  13. ContextOptions<DateType> {}
  14. /**
  15. * @name startOfWeek
  16. * @category Week Helpers
  17. * @summary Return the start of a week for the given date.
  18. *
  19. * @description
  20. * Return the start of a week for the given date.
  21. * The result will be in the local timezone.
  22. *
  23. * @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).
  24. * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
  25. *
  26. * @param date - The original date
  27. * @param options - An object with options
  28. *
  29. * @returns The start of a week
  30. *
  31. * @example
  32. * // The start of a week for 2 September 2014 11:55:00:
  33. * const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0))
  34. * //=> Sun Aug 31 2014 00:00:00
  35. *
  36. * @example
  37. * // If the week starts on Monday, the start of the week for 2 September 2014 11:55:00:
  38. * const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0), { weekStartsOn: 1 })
  39. * //=> Mon Sep 01 2014 00:00:00
  40. */
  41. export declare function startOfWeek<
  42. DateType extends Date,
  43. ResultDate extends Date = DateType,
  44. >(
  45. date: DateArg<DateType>,
  46. options?: StartOfWeekOptions<ResultDate>,
  47. ): ResultDate;