Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | 1x 1x 1x 1x 1x 1x 100x 100x 100x 1x 1x 1x 1x 1x 1x 20x 20x 20x 1x 1x 42x 42x 1x 1x 5x 5x 1x 1x 44x 44x 1x 1x 7x 7x 1x 1x 26x 26x 1x 1x 1x 1x 1x 1x 20x 20x 1x 1x 1x 1x 26x 26x 1x 1x 2x 2x 1x 1x 1x 1x 1x 9x 9x 1x 1x 1x 1x 1x 1x 1x 11x 6x 4x 4x 2x 1x 1x 5x 5x 11x 4x 1x 1x 3x 1x 1x 2x 1x 1x 3x 3x 11x 11x 11x 1x 1x 9x 11x 1x 1x 1x 1x 1x 1x 1x 11x 55x 55x 21x 21x 21x 34x 55x 11x 11x 11x 1x 1x 1x | // @ts-check /** * @param {string} value * @returns {string|Number} */ function toNum(value) { return (/^\d+$/.test(value)) ? Number(value) : value; } class CronRule { /** * @param {string} rule */ constructor(rule) { this.items = rule?.split?.(' ', 5).map(toNum); if (this.items?.length !== 5) { throw new Error(`failed to parse Cron rule: ${rule}`); } } get minute() { return this.items[0]; } set minute(value) { this.items[0] = value; } get hour() { return this.items[1]; } set hour(value) { this.items[1] = value; } get dayOfMonth() { return this.items[2]; } set dayOfMonth(value) { this.items[2] = value; } get month() { return this.items[3]; } set month(value) { this.items[3] = value; } get dayOfWeek() { return this.items[4]; } set dayOfWeek(value) { this.items[4] = value; } /** * @returns {string} */ toRule() { return `${this.minute} ${this.hour} ${this.dayOfMonth} ${this.month} ${this.dayOfWeek}`; } /** * @param {boolean} [strict=false] * @returns {CronRule} */ // eslint-disable-next-line complexity normalize(strict = false) { if (typeof this.minute === 'number' && this.minute >= 60) { if (typeof this.hour === 'number') { this.hour += Math.trunc(this.minute / 60); } else if (strict) { throw new Error(`failed to normalize ${this.toRule()}`); } this.minute %= 60; } if (typeof this.hour === 'number' && this.hour >= 24) { if (typeof this.dayOfMonth === 'number') { this.dayOfMonth += Math.trunc(this.hour / 24); } else if (typeof this.dayOfWeek === 'number') { this.dayOfWeek += Math.trunc(this.hour / 24); } else if (strict) { throw new Error(`failed to normalize ${this.toRule()}`); } this.hour %= 24; } if (typeof this.dayOfMonth === 'number' && this.dayOfMonth > 31) { this.dayOfMonth = (this.dayOfMonth % 31) + 1; } if (typeof this.month === 'number' && this.month > 12) { this.month = (this.month % 12) + 1; } if (typeof this.dayOfWeek === 'number' && this.dayOfWeek >= 7) { this.dayOfWeek %= 7; } return this; } /** * @param {CronRule} rule * @param {boolean} strict silently discard errors * @returns {CronRule} */ increment(rule, strict = false) { for (let idx = 0; idx < this.items.length; ++idx) { if (typeof (rule?.items?.[idx]) !== 'number') { continue; } else if (typeof this.items[idx] === 'number') { // @ts-ignore this.items[idx] += rule.items[idx]; } else if (strict && rule.items[idx] !== 0) { throw new Error(`can't add ${rule?.toRule()} to ${this.toRule()}`); } } this.normalize(strict); return this; } } export default CronRule; |