(out: Set<number>, term: string, min: number, max: number, name: string)
| 128 | } |
| 129 | |
| 130 | function addTerm(out: Set<number>, term: string, min: number, max: number, name: string): void { |
| 131 | let rangePart = term; |
| 132 | let step = 1; |
| 133 | const slash = term.indexOf('/'); |
| 134 | if (slash !== -1) { |
| 135 | rangePart = term.slice(0, slash); |
| 136 | const stepStr = term.slice(slash + 1); |
| 137 | if (stepStr === '') { |
| 138 | throw new Error(`cron ${name} step is empty in "${term}"`); |
| 139 | } |
| 140 | const parsedStep = parseCronInt(stepStr, name, 'step'); |
| 141 | if (parsedStep <= 0) { |
| 142 | throw new Error(`cron ${name} step must be a positive integer (got "${stepStr}")`); |
| 143 | } |
| 144 | step = parsedStep; |
| 145 | if (rangePart === '') { |
| 146 | throw new Error(`cron ${name} step needs a range or "*" before "/" in "${term}"`); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | let lo: number; |
| 151 | let hi: number; |
| 152 | if (rangePart === '*') { |
| 153 | lo = min; |
| 154 | hi = max; |
| 155 | } else { |
| 156 | const dash = rangePart.indexOf('-'); |
| 157 | if (dash === -1) { |
| 158 | const single = parseCronInt(rangePart, name, 'value'); |
| 159 | if (single < min || single > max) { |
| 160 | throw new Error(`cron ${name} value ${single} out of range ${min}..${max}`); |
| 161 | } |
| 162 | // A bare single value with a step (`5/10`) is unusual; treat as |
| 163 | // "from value through max stepping by N", which is what most cron |
| 164 | // dialects do. |
| 165 | if (slash !== -1) { |
| 166 | lo = single; |
| 167 | hi = max; |
| 168 | } else { |
| 169 | out.add(single); |
| 170 | return; |
| 171 | } |
| 172 | } else { |
| 173 | const loStr = rangePart.slice(0, dash); |
| 174 | const hiStr = rangePart.slice(dash + 1); |
| 175 | lo = parseCronInt(loStr, name, 'range lower bound'); |
| 176 | hi = parseCronInt(hiStr, name, 'range upper bound'); |
| 177 | if (lo < min || hi > max || lo > hi) { |
| 178 | throw new Error( |
| 179 | `cron ${name} range ${lo}-${hi} out of bounds (must be ${min}..${max}, ascending)`, |
| 180 | ); |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | for (let v = lo; v <= hi; v += step) { |
| 186 | out.add(v); |
| 187 | } |
no test coverage detected