MCPcopy Create free account
hub / github.com/Fibi66/FeiControl / getNextRuns

Function getNextRuns

src/lib/cron-parser.ts:197–225  ·  view source on GitHub ↗
(
  expr: string,
  count: number = 3,
  fromDate: Date = new Date(),
  timezone: string = 'UTC'
)

Source from the content-addressed store, hash-verified

195 * @returns Array of Date objects representing next run times
196 */
197export function getNextRuns(
198 expr: string,
199 count: number = 3,
200 fromDate: Date = new Date(),
201 timezone: string = 'UTC'
202): Date[] {
203 const parts = parseCron(expr);
204 if (!parts) return [];
205
206 const runs: Date[] = [];
207 const maxIterations = 525600; // Max 1 year of minutes
208
209 // Start from the next minute
210 const current = new Date(fromDate);
211 current.setSeconds(0);
212 current.setMilliseconds(0);
213 current.setMinutes(current.getMinutes() + 1);
214
215 let iterations = 0;
216 while (runs.length < count && iterations < maxIterations) {
217 if (matchesCron(current, parts)) {
218 runs.push(new Date(current));
219 }
220 current.setMinutes(current.getMinutes() + 1);
221 iterations++;
222 }
223
224 return runs;
225}
226
227/**
228 * Validate a cron expression

Callers 2

CronWeeklyTimelineFunction · 0.90
CronJobModalFunction · 0.90

Calls 2

parseCronFunction · 0.85
matchesCronFunction · 0.85

Tested by

no test coverage detected