| 69 | } |
| 70 | |
| 71 | function parseFieldValues(field: string): number[] | null { |
| 72 | const result: number[] = [] |
| 73 | |
| 74 | for (const part of field.split(',')) { |
| 75 | const stepMatch = /^(\*|\d+-\d+)\/(\d+)$/.exec(part) |
| 76 | if (stepMatch) { |
| 77 | const step = Number(stepMatch[2]) |
| 78 | if (step === 0) return null |
| 79 | let start: number, end: number |
| 80 | if (stepMatch[1] === '*') { |
| 81 | start = 0 |
| 82 | end = 59 |
| 83 | } else { |
| 84 | const [a, b] = stepMatch[1].split('-').map(Number) |
| 85 | start = a |
| 86 | end = b |
| 87 | } |
| 88 | for (let i = start; i <= end; i += step) result.push(i) |
| 89 | continue |
| 90 | } |
| 91 | |
| 92 | const rangeMatch = /^(\d+)-(\d+)$/.exec(part) |
| 93 | if (rangeMatch) { |
| 94 | const a = Number(rangeMatch[1]) |
| 95 | const b = Number(rangeMatch[2]) |
| 96 | for (let i = a; i <= b; i++) result.push(i) |
| 97 | continue |
| 98 | } |
| 99 | |
| 100 | if (part === '*') { |
| 101 | for (let i = 0; i <= 59; i++) result.push(i) |
| 102 | continue |
| 103 | } |
| 104 | |
| 105 | const n = Number(part) |
| 106 | if (Number.isNaN(n)) return null |
| 107 | result.push(n) |
| 108 | } |
| 109 | |
| 110 | return result.length > 0 ? result : null |
| 111 | } |