(cronExpression: string, timezone?: string)
| 511 | * @returns Human-readable description of the schedule |
| 512 | */ |
| 513 | export const parseCronToHumanReadable = (cronExpression: string, timezone?: string): string => { |
| 514 | try { |
| 515 | const forDisplay = cronExpression.replace(/([0-7])#L\b/g, '$1L') |
| 516 | const baseDescription = cronstrue |
| 517 | .toString(forDisplay, { |
| 518 | use24HourTimeFormat: false, |
| 519 | verbose: false, |
| 520 | }) |
| 521 | .replace(/\b0(\d:\d{2})/g, '$1') |
| 522 | |
| 523 | if (timezone && timezone !== 'UTC') { |
| 524 | const tzAbbr = getTimezoneAbbreviation(timezone) |
| 525 | return `${baseDescription} (${tzAbbr})` |
| 526 | } |
| 527 | |
| 528 | return baseDescription |
| 529 | } catch (error) { |
| 530 | logger.warn('Failed to parse cron expression with cronstrue:', { |
| 531 | cronExpression, |
| 532 | error: toError(error).message, |
| 533 | }) |
| 534 | return `Schedule: ${cronExpression}${timezone && timezone !== 'UTC' ? ` (${getTimezoneAbbreviation(timezone)})` : ''}` |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | const REVERSE_DAY_MAP: Record<number, string> = { |
| 539 | 0: 'SUN', |
no test coverage detected