/* eslint-disable eslint-comments/no-unlimited-disable */ /* eslint-disable */ // @ts-nocheck import { normalizeInterval } from '../_lib/normalizeInterval/index.ts'; import { constructFrom } from '../constructFrom/index.ts'; import { eachDayOfInterval } from '../eachDayOfInterval/index.ts'; import { isWeekend } from '../isWeekend/index.ts'; import type { ContextOptions, Interval } from '../types.ts'; /** * The {@link eachWeekendOfInterval} function options. */ export interface EachWeekendOfIntervalOptions extends ContextOptions {} /** * The {@link eachWeekendOfInterval} function result type. */ export type EachWeekendOfIntervalResult< IntervalType extends Interval, Options extends EachWeekendOfIntervalOptions | undefined, > = Array< Options extends EachWeekendOfIntervalOptions ? DateType : IntervalType['start'] extends Date ? IntervalType['start'] : IntervalType['end'] extends Date ? IntervalType['end'] : Date >; /** * @name eachWeekendOfInterval * @category Interval Helpers * @summary List all the Saturdays and Sundays in the given date interval. * * @description * Get all the Saturdays and Sundays in the given date interval. * * @typeParam IntervalType - Interval type. * @typeParam Options - Options type. * * @param interval - The given interval * @param options - An object with options * * @returns An array containing all the Saturdays and Sundays * * @example * // Lists all Saturdays and Sundays in the given date interval * const result = eachWeekendOfInterval({ * start: new Date(2018, 8, 17), * end: new Date(2018, 8, 30) * }) * //=> [ * // Sat Sep 22 2018 00:00:00, * // Sun Sep 23 2018 00:00:00, * // Sat Sep 29 2018 00:00:00, * // Sun Sep 30 2018 00:00:00 * // ] */ export function eachWeekendOfInterval< IntervalType extends Interval, Options extends EachWeekendOfIntervalOptions | undefined = undefined, >(interval: IntervalType, options?: Options): EachWeekendOfIntervalResult { const { start, end } = normalizeInterval(options?.in, interval); const dateInterval = eachDayOfInterval({ start, end }, options); const weekends: EachWeekendOfIntervalResult = []; let index = 0; while (index < dateInterval.length) { const date = dateInterval[index++]; if (isWeekend(date)) weekends.push(constructFrom(start, date)); } return weekends; } /* eslint-enable */