eachYearOfInterval.d.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import type { ContextOptions, Interval, StepOptions } from "./types.js";
  2. /**
  3. * The {@link eachYearOfInterval} function options.
  4. */
  5. export interface EachYearOfIntervalOptions<DateType extends Date = Date>
  6. extends StepOptions,
  7. ContextOptions<DateType> {}
  8. /**
  9. * The {@link eachYearOfInterval} function result type. It resolves the proper data type.
  10. * It uses the first argument date object type, starting from the date argument,
  11. * then the start interval date, and finally the end interval date. If
  12. * a context function is passed, it uses the context function return type.
  13. */
  14. export type EachYearOfIntervalResult<
  15. IntervalType extends Interval,
  16. Options extends EachYearOfIntervalOptions | undefined,
  17. > = Array<
  18. Options extends EachYearOfIntervalOptions<infer DateType>
  19. ? DateType
  20. : IntervalType["start"] extends Date
  21. ? IntervalType["start"]
  22. : IntervalType["end"] extends Date
  23. ? IntervalType["end"]
  24. : Date
  25. >;
  26. /**
  27. * @name eachYearOfInterval
  28. * @category Interval Helpers
  29. * @summary Return the array of yearly timestamps within the specified time interval.
  30. *
  31. * @description
  32. * Return the array of yearly timestamps within the specified time interval.
  33. *
  34. * @typeParam IntervalType - Interval type.
  35. * @typeParam Options - Options type.
  36. *
  37. * @param interval - The interval.
  38. * @param options - An object with options.
  39. *
  40. * @returns The array with starts of yearly timestamps from the month of the interval start to the month of the interval end
  41. *
  42. * @example
  43. * // Each year between 6 February 2014 and 10 August 2017:
  44. * const result = eachYearOfInterval({
  45. * start: new Date(2014, 1, 6),
  46. * end: new Date(2017, 7, 10)
  47. * })
  48. * //=> [
  49. * // Wed Jan 01 2014 00:00:00,
  50. * // Thu Jan 01 2015 00:00:00,
  51. * // Fri Jan 01 2016 00:00:00,
  52. * // Sun Jan 01 2017 00:00:00
  53. * // ]
  54. */
  55. export declare function eachYearOfInterval<
  56. IntervalType extends Interval,
  57. Options extends EachYearOfIntervalOptions | undefined = undefined,
  58. >(
  59. interval: IntervalType,
  60. options?: Options,
  61. ): EachYearOfIntervalResult<IntervalType, Options>;