![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/lavocat.ca/public_html/node_modules/date-fns/ |
import { addWeeks } from "./addWeeks.mjs";
import { startOfWeek } from "./startOfWeek.mjs";
import { toDate } from "./toDate.mjs";
/**
* The {@link eachWeekOfInterval} function options.
*/
/**
* @name eachWeekOfInterval
* @category Interval Helpers
* @summary Return the array of weeks within the specified time interval.
*
* @description
* Return the array of weeks within the specified time interval.
*
* @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).
*
* @param interval - The interval.
* @param options - An object with options.
*
* @returns The array with starts of weeks from the week of the interval start to the week of the interval end
*
* @example
* // Each week within interval 6 October 2014 - 23 November 2014:
* const result = eachWeekOfInterval({
* start: new Date(2014, 9, 6),
* end: new Date(2014, 10, 23)
* })
* //=> [
* // Sun Oct 05 2014 00:00:00,
* // Sun Oct 12 2014 00:00:00,
* // Sun Oct 19 2014 00:00:00,
* // Sun Oct 26 2014 00:00:00,
* // Sun Nov 02 2014 00:00:00,
* // Sun Nov 09 2014 00:00:00,
* // Sun Nov 16 2014 00:00:00,
* // Sun Nov 23 2014 00:00:00
* // ]
*/
export function eachWeekOfInterval(interval, options) {
const startDate = toDate(interval.start);
const endDate = toDate(interval.end);
let reversed = +startDate > +endDate;
const startDateWeek = reversed
? startOfWeek(endDate, options)
: startOfWeek(startDate, options);
const endDateWeek = reversed
? startOfWeek(startDate, options)
: startOfWeek(endDate, options);
// Some timezones switch DST at midnight, making start of day unreliable in these timezones, 3pm is a safe bet
startDateWeek.setHours(15);
endDateWeek.setHours(15);
const endTime = +endDateWeek.getTime();
let currentDate = startDateWeek;
let step = options?.step ?? 1;
if (!step) return [];
if (step < 0) {
step = -step;
reversed = !reversed;
}
const dates = [];
while (+currentDate <= endTime) {
currentDate.setHours(0);
dates.push(toDate(currentDate));
currentDate = addWeeks(currentDate, step);
currentDate.setHours(15);
}
return reversed ? dates.reverse() : dates;
}
// Fallback for modularized imports:
export default eachWeekOfInterval;