MCPcopy Index your code
hub / github.com/simstudioai/sim / generateCronExpression

Function generateCronExpression

apps/sim/lib/workflows/schedules/utils.ts:326–362  ·  view source on GitHub ↗
(
  scheduleType: string,
  scheduleValues: ReturnType<typeof getScheduleTimeValues>
)

Source from the content-addressed store, hash-verified

324 * @returns Cron expression string representing the schedule in local time
325 */
326export function generateCronExpression(
327 scheduleType: string,
328 scheduleValues: ReturnType<typeof getScheduleTimeValues>
329): string {
330 switch (scheduleType) {
331 case 'minutes':
332 return `*/${scheduleValues.minutesInterval} * * * *`
333
334 case 'hourly':
335 return `${scheduleValues.hourlyMinute} * * * *`
336
337 case 'daily': {
338 const [hours, minutes] = scheduleValues.dailyTime
339 return `${minutes} ${hours} * * *`
340 }
341
342 case 'weekly': {
343 const [hours, minutes] = scheduleValues.weeklyTime
344 return `${minutes} ${hours} * * ${scheduleValues.weeklyDay}`
345 }
346
347 case 'monthly': {
348 const [hours, minutes] = scheduleValues.monthlyTime
349 return `${minutes} ${hours} ${scheduleValues.monthlyDay} * *`
350 }
351
352 case 'custom': {
353 if (!scheduleValues.cronExpression?.trim()) {
354 throw new Error('Custom schedule requires a valid cron expression')
355 }
356 return scheduleValues.cronExpression
357 }
358
359 default:
360 throw new Error(`Unsupported schedule type: ${scheduleType}`)
361 }
362}
363
364/**
365 * Calculate the next run time based on schedule configuration

Callers 3

utils.test.tsFile · 0.90
validateScheduleBlockFunction · 0.90
calculateNextRunTimeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected