@@ -231,21 +231,28 @@ const checkTaskDates = function (task, dateFormat, excludes, includes) {
231231 * @param {dayjs.Dayjs } startTime - The start time.
232232 * @param {dayjs.Dayjs } endTime - The original end time (will return a different end time if it's invalid).
233233 * @param {string } dateFormat - Dayjs date format string.
234- * @param {* } excludes
235- * @param {* } includes
234+ * @param {string[] } excludes - Dates or days to exclude.
235+ * @param {string[] } includes - Dates to always include, even if they match the excludes.
236236 * @returns {[endTime: dayjs.Dayjs, renderEndTime: Date | null] } The new `endTime`, and the end time to render.
237237 * `renderEndTime` may be `null` if `startTime` is newer than `endTime`.
238+ * @throws {Error } If a valid end time cannot be found after 10,000 iterations.
238239 */
239240const fixTaskDates = function ( startTime , endTime , dateFormat , excludes , includes ) {
240241 let invalid = false ;
241242 let renderEndTime = null ;
243+ const maxEndTime = endTime . add ( 10000 , 'd' ) ;
242244 while ( startTime <= endTime ) {
243245 if ( ! invalid ) {
244246 renderEndTime = endTime . toDate ( ) ;
245247 }
246248 invalid = isInvalidDate ( startTime , dateFormat , excludes , includes ) ;
247249 if ( invalid ) {
248250 endTime = endTime . add ( 1 , 'd' ) ;
251+ if ( endTime > maxEndTime ) {
252+ throw new Error (
253+ 'Failed to find a valid date that was not excluded by `excludes` after 10,000 iterations.'
254+ ) ;
255+ }
249256 }
250257 startTime = startTime . add ( 1 , 'd' ) ;
251258 }
0 commit comments