fix(front): describe cron minute patterns with fixed or listed hours

Merged
HA
2d ago
+152-1

Fixes #28811

Description

Cron expressions that combine a wildcard, step, range or list minute field with a fixed or listed hour field produced broken descriptions:

ExpressionBeforeAfter
*/5 9 * * *at every 5 minutes between 09:00 and 09:59 UTC
* 9 * * *at every minute between 09:00 and 09:59 UTC
*/10 9,17 * * *at and every 10 minutes during 09:00 and 17:00 UTC
* 9,17 * * 1-5at and on weekdaysevery minute during 09:00 and 17:00 UTC on weekdays
0-30 9 * * *at 09:00 UTCevery minute from 09:00 to 09:30 UTC

Expressions that were already correct keep their descriptions, e.g. 30 14 * * * → at 14:30 UTC, 30 9,14 * * * → at 09:30 UTC and 14:30 UTC, */15 9-17 * * 1-5 → every 15 minutes between 09:00 UTC and 17:00 UTC on weekdays, * * * * * → every minute.

Root cause

In describeCronExpression, the minutes description was only given priority when the hour field was * or contained -. For a fixed or listed hour, getHoursDescription formatted the hour as a single time with the raw minute string, and formatTime returns '' when parseInt on the minute value is NaN (*, */5), yielding at / at and . 0-30 parses as 0, so the range collapsed to a single time.

Fix

  • describeCronExpression: when the minute field is a pattern (*, step, range, list) and the hour field is a single value or a list, compose the minutes description with the hour window instead of formatting a single time.
  • getHoursDescription: return '' when the minute value cannot be formatted as a time, so a broken at string never reaches the output (the caller then falls back to the minutes description).

Tests

  • New cases in describeCronExpression.test.ts for the five broken expressions above, plus listed minutes with a fixed hour, more than two listed hours, and 12-hour format.
  • New cases in getHoursDescription.test.ts for the empty-string contract with non-numeric minutes.
  • All 113 cron-to-human tests pass; tsgo --noEmit typecheck on twenty-front is clean.