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

Function detectStep

packages/agent-core/src/tools/cron/cron-expr.ts:420–434  ·  view source on GitHub ↗

* If the set looks like `{min, min+step, ..., <=max}` with a constant * step, return `step`. Otherwise null. Used to pretty-print star-slash-N.

(set: ReadonlySet<number>, min: number, max: number)

Source from the content-addressed store, hash-verified

418 * step, return `step`. Otherwise null. Used to pretty-print star-slash-N.
419 */
420function detectStep(set: ReadonlySet<number>, min: number, max: number): number | null {
421 const values = [...set].toSorted((a, b) => a - b);
422 if (values.length < 2) return null;
423 if (values[0] !== min) return null;
424 const step = values[1]! - values[0]!;
425 if (step <= 0) return null;
426 let expected = min;
427 for (const v of values) {
428 if (v !== expected) return null;
429 expected += step;
430 }
431 // The last expected value should exceed `max` by less than `step`.
432 if (expected - step > max) return null;
433 return step;
434}
435
436function formatDows(set: ReadonlySet<number>): string | null {
437 const values = [...set].toSorted((a, b) => a - b);

Callers 1

cronToHumanFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected