MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / parseField

Function parseField

src/schedule/cron.ts:61–90  ·  view source on GitHub ↗
(field: string, [min, max]: [number, number], idx: number)

Source from the content-addressed store, hash-verified

59}
60
61function parseField(field: string, [min, max]: [number, number], idx: number): Set<number> {
62 const out = new Set<number>();
63 for (const segment of field.split(',')) {
64 let step = 1;
65 let body = segment;
66 if (segment.includes('/')) {
67 const [b, s] = segment.split('/');
68 body = b!;
69 step = parseInt(s!, 10);
70 if (!Number.isFinite(step) || step <= 0) throw new Error(`Invalid step in cron field ${idx}: "${segment}"`);
71 }
72 let lo: number, hi: number;
73 if (body === '*') {
74 lo = min; hi = max;
75 } else if (body.includes('-')) {
76 const [a, b] = body.split('-');
77 lo = parseInt(a!, 10); hi = parseInt(b!, 10);
78 } else {
79 lo = hi = parseInt(body, 10);
80 }
81 if (!Number.isFinite(lo) || !Number.isFinite(hi)) {
82 throw new Error(`Invalid cron field ${idx}: "${segment}"`);
83 }
84 if (lo < min || hi > max || lo > hi) {
85 throw new Error(`Cron field ${idx} out of range [${min},${max}]: "${segment}"`);
86 }
87 for (let v = lo; v <= hi; v += step) out.add(v);
88 }
89 return out;
90}
91
92/** Does the given Date match the cron expression at minute precision? */
93export function matches(cron: CronExpression, when: Date): boolean {

Callers 1

parseCronFunction · 0.85

Calls 1

addMethod · 0.80

Tested by

no test coverage detected