MCPcopy
hub / github.com/simstudioai/sim / validateCronExpression

Function validateCronExpression

apps/sim/lib/workflows/schedules/utils.ts:15–51  ·  view source on GitHub ↗
(
  cronExpression: string,
  timezone?: string
)

Source from the content-addressed store, hash-verified

13 * @returns Validation result with isValid flag, error message, and next run date
14 */
15export function validateCronExpression(
16 cronExpression: string,
17 timezone?: string
18): {
19 isValid: boolean
20 error?: string
21 nextRun?: Date
22} {
23 if (!cronExpression?.trim()) {
24 return {
25 isValid: false,
26 error: 'Cron expression cannot be empty',
27 }
28 }
29
30 try {
31 const cron = new Cron(cronExpression, timezone ? { timezone } : undefined)
32 const nextRun = cron.nextRun()
33
34 if (!nextRun) {
35 return {
36 isValid: false,
37 error: 'Cron expression produces no future occurrences',
38 }
39 }
40
41 return {
42 isValid: true,
43 nextRun,
44 }
45 } catch (error) {
46 return {
47 isValid: false,
48 error: getErrorMessage(error, 'Invalid cron expression syntax'),
49 }
50 }
51}
52
53/** Upper bound on how many excluded occurrences the next-run search skips before giving up. */
54const MAX_OCCURRENCE_SKIP = 1000

Callers 5

utils.test.tsFile · 0.90
performCreateJobFunction · 0.90
performUpdateJobFunction · 0.90
validateScheduleBlockFunction · 0.90
route.tsFile · 0.90

Calls 1

getErrorMessageFunction · 0.90

Tested by

no test coverage detected