MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / cronToHuman

Function cronToHuman

packages/agent-core/src/tools/cron/cron-expr.ts:350–408  ·  view source on GitHub ↗
(expr: ParsedCronExpression)

Source from the content-addressed store, hash-verified

348 * is fine and we don't try to be exhaustive.
349 */
350export function cronToHuman(expr: ParsedCronExpression): string {
351 const allMin = isFullRange(expr.minutes, 0, 59);
352 const allHour = isFullRange(expr.hours, 0, 23);
353 const allDom = expr.daysOfMonthWildcard;
354 const allMonth = isFullRange(expr.months, 1, 12);
355 const allDow = expr.daysOfWeekWildcard;
356
357 // every N minutes — common LLM pattern (`*/5 * * * *`).
358 if (allHour && allDom && allMonth && allDow) {
359 const step = detectStep(expr.minutes, 0, 59);
360 if (step !== null && step > 1) return `every ${step} minutes`;
361 if (allMin) return 'every minute';
362 if (expr.minutes.size === 1) {
363 const m = [...expr.minutes][0]!;
364 return `at minute ${m} of every hour`;
365 }
366 }
367
368 // every N hours.
369 if (expr.minutes.size === 1 && allDom && allMonth && allDow) {
370 const m = [...expr.minutes][0]!;
371 const step = detectStep(expr.hours, 0, 23);
372 if (step !== null && step > 1) {
373 return `every ${step} hours at minute ${pad(m)}`;
374 }
375 }
376
377 // at HH:MM every day, optional dow restriction.
378 if (
379 expr.minutes.size === 1 &&
380 expr.hours.size === 1 &&
381 allDom &&
382 allMonth
383 ) {
384 const h = [...expr.hours][0]!;
385 const m = [...expr.minutes][0]!;
386 if (allDow) return `at ${pad(h)}:${pad(m)} every day`;
387 const dowStr = formatDows(expr.daysOfWeek);
388 if (dowStr !== null) return `at ${pad(h)}:${pad(m)} on ${dowStr}`;
389 }
390
391 // at HH:MM on day N of <month>.
392 if (
393 expr.minutes.size === 1 &&
394 expr.hours.size === 1 &&
395 expr.daysOfMonth.size === 1 &&
396 !expr.daysOfMonthWildcard &&
397 expr.months.size === 1 &&
398 allDow
399 ) {
400 const h = [...expr.hours][0]!;
401 const m = [...expr.minutes][0]!;
402 const d = [...expr.daysOfMonth][0]!;
403 const mo = [...expr.months][0]!;
404 return `at ${pad(h)}:${pad(m)} on day ${d} of ${MONTH_NAMES[mo - 1]}`;
405 }
406
407 return expr.raw;

Callers 3

cron-expr.test.tsFile · 0.90
renderRecordMethod · 0.90
resolveExecutionMethod · 0.90

Calls 4

isFullRangeFunction · 0.85
detectStepFunction · 0.85
formatDowsFunction · 0.85
padFunction · 0.70

Tested by

no test coverage detected