fix: improve CRON schedule validation and display (#16360)

Fixes multiple issues with CRON schedule input validation and execution
time display.

### Issues Fixed

1. **UTC label placement** - Added "UTC" suffix to specific times (e.g.,
"at 09:30 UTC") but not to interval descriptions (e.g., "every hour")

2. **Upcoming execution time calculation** - Fixed incorrect execution
times for malformed CRON expressions by implementing auto-correction

### Changes

- Created `normalizeCronExpression` utility to standardize cron
expressions before parsing
- Updated `formatTime` to support optional UTC suffix
- Enhanced `getHoursDescription` to append UTC to specific times
- Added comprehensive test coverage (102 tests passing)

### Before

- `"1 /3 * * *"` showed daily executions at same time (incorrect)
- `"9 * * *"` showed same time repeated 3 times (incorrect)
- No UTC labels on schedule descriptions (confusing)

### After

- All malformed expressions auto-corrected and show correct execution
times
- UTC labels clearly indicate timezone for specific times
- User-friendly error messages for truly invalid patterns

Closes #15870
This commit is contained in:
Abdul Rahman
2025-12-09 00:09:11 +05:30
committed by GitHub
parent f80b2f2c38
commit 77e592502c
15 changed files with 350 additions and 89 deletions
@@ -220,12 +220,19 @@ function assertCronTriggerSettingsAreValid(settings: any) {
);
}
if (settings.schedule.minute <= 0) {
if (settings.schedule.minute <= 0 || settings.schedule.minute > 60) {
const errorMessage =
settings.schedule.minute <= 0
? msg`Invalid minute value. Should be integer greater than 1`
: msg`Minute value cannot exceed 60. For intervals greater than 60 minutes, use the "Hours" trigger type or a custom cron expression`;
throw new WorkflowTriggerException(
'Invalid minute value. Should be integer greater than 1',
settings.schedule.minute <= 0
? 'Invalid minute value. Should be integer greater than 1'
: 'Invalid minute value. Cannot exceed 60. For intervals greater than 60 minutes, use the "Hours" trigger type or a custom cron expression',
WorkflowTriggerExceptionCode.INVALID_WORKFLOW_TRIGGER,
{
userFriendlyMessage: msg`Invalid minute value. Should be integer greater than 1`,
userFriendlyMessage: errorMessage,
},
);
}