eachWeekOfInterval.d.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import type {
  2. ContextOptions,
  3. Interval,
  4. LocalizedOptions,
  5. StepOptions,
  6. WeekOptions,
  7. } from "./types.js";
  8. /**
  9. * The {@link eachWeekOfInterval} function options.
  10. */
  11. export interface EachWeekOfIntervalOptions<DateType extends Date = Date>
  12. extends StepOptions,
  13. WeekOptions,
  14. LocalizedOptions<"options">,
  15. ContextOptions<DateType> {}
  16. /**
  17. * The {@link eachWeekOfInterval} function result type. It resolves the proper data type.
  18. * It uses the first argument date object type, starting from the interval start date,
  19. * then the end interval date. If a context function is passed, it uses the context function return type.
  20. */
  21. export type EachWeekOfIntervalResult<
  22. IntervalType extends Interval,
  23. Options extends EachWeekOfIntervalOptions | undefined,
  24. > = Array<
  25. Options extends EachWeekOfIntervalOptions<infer DateType>
  26. ? DateType
  27. : IntervalType["start"] extends Date
  28. ? IntervalType["start"]
  29. : IntervalType["end"] extends Date
  30. ? IntervalType["end"]
  31. : Date
  32. >;
  33. /**
  34. * @name eachWeekOfInterval
  35. * @category Interval Helpers
  36. * @summary Return the array of weeks within the specified time interval.
  37. *
  38. * @description
  39. * Return the array of weeks within the specified time interval.
  40. *
  41. * @param interval - The interval.
  42. * @param options - An object with options.
  43. *
  44. * @returns The array with starts of weeks from the week of the interval start to the week of the interval end
  45. *
  46. * @example
  47. * // Each week within interval 6 October 2014 - 23 November 2014:
  48. * const result = eachWeekOfInterval({
  49. * start: new Date(2014, 9, 6),
  50. * end: new Date(2014, 10, 23)
  51. * })
  52. * //=> [
  53. * // Sun Oct 05 2014 00:00:00,
  54. * // Sun Oct 12 2014 00:00:00,
  55. * // Sun Oct 19 2014 00:00:00,
  56. * // Sun Oct 26 2014 00:00:00,
  57. * // Sun Nov 02 2014 00:00:00,
  58. * // Sun Nov 09 2014 00:00:00,
  59. * // Sun Nov 16 2014 00:00:00,
  60. * // Sun Nov 23 2014 00:00:00
  61. * // ]
  62. */
  63. export declare function eachWeekOfInterval<
  64. IntervalType extends Interval,
  65. Options extends EachWeekOfIntervalOptions | undefined = undefined,
  66. >(
  67. interval: IntervalType,
  68. options?: Options,
  69. ): EachWeekOfIntervalResult<IntervalType, Options>;