( scheduleType: string, scheduleValues: ReturnType<typeof getScheduleTimeValues> )
| 324 | * @returns Cron expression string representing the schedule in local time |
| 325 | */ |
| 326 | export 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 |
no outgoing calls
no test coverage detected