@@ -251,21 +251,28 @@ const checkTaskDates = function (task, dateFormat, excludes, includes) {
251251 * @param {dayjs.Dayjs } startTime - The start time.
252252 * @param {dayjs.Dayjs } endTime - The original end time (will return a different end time if it's invalid).
253253 * @param {string } dateFormat - Dayjs date format string.
254- * @param {* } excludes
255- * @param {* } includes
254+ * @param {string[] } excludes - Dates or days to exclude.
255+ * @param {string[] } includes - Dates to always include, even if they match the excludes.
256256 * @returns {[endTime: dayjs.Dayjs, renderEndTime: Date | null] } The new `endTime`, and the end time to render.
257257 * `renderEndTime` may be `null` if `startTime` is newer than `endTime`.
258+ * @throws {Error } If a valid end time cannot be found after 10,000 iterations.
258259 */
259260const fixTaskDates = function ( startTime , endTime , dateFormat , excludes , includes ) {
260261 let invalid = false ;
261262 let renderEndTime = null ;
263+ const maxEndTime = endTime . add ( 10000 , 'd' ) ;
262264 while ( startTime <= endTime ) {
263265 if ( ! invalid ) {
264266 renderEndTime = endTime . toDate ( ) ;
265267 }
266268 invalid = isInvalidDate ( startTime , dateFormat , excludes , includes ) ;
267269 if ( invalid ) {
268270 endTime = endTime . add ( 1 , 'd' ) ;
271+ if ( endTime > maxEndTime ) {
272+ throw new Error (
273+ 'Failed to find a valid date that was not excluded by `excludes` after 10,000 iterations.'
274+ ) ;
275+ }
269276 }
270277 startTime = startTime . add ( 1 , 'd' ) ;
271278 }
0 commit comments