|
| 1 | +export const minuteExp = `(0?[0-9]|[1-5][0-9])`; // [0]0-59 |
| 2 | +export const hourExp = `(0?[0-9]|1[0-9]|2[0-3])`; // [0]0-23 |
| 3 | +export const dayOfMonthExp = `(0?[1-9]|[1-2][0-9]|3[0-1])`; // [0]1-31 |
| 4 | +export const monthExp = `(0?[1-9]|1[0-2]|JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)`; // [0]1-12 or JAN-DEC |
| 5 | +export const dayOfWeekExp = `([1-7]|SUN|MON|TUE|WED|THU|FRI|SAT)`; // 1-7 or SAT-SUN |
| 6 | +export const yearExp = `((19[8-9][0-9])|(2[0-1][0-9][0-9]))`; // 1980-2199 |
| 7 | +export const numbers = `([0-9]*[1-9][0-9]*)`; // whole numbers greater than 0 |
| 8 | + |
| 9 | +export function dayOfWeekHash(): string { |
| 10 | + return `(${dayOfWeekExp}#[1-5])`; // add hash expression to enable supported use case |
| 11 | +} |
| 12 | + |
| 13 | +function rangeRegex(values: string): string { |
| 14 | + return `(${values}|(\\*\\-${values})|(${values}\\-${values})|(${values}\\-\\*))`; |
| 15 | +} |
| 16 | + |
| 17 | +function listRangeRegex(values: string): string { |
| 18 | + const range = rangeRegex(values); |
| 19 | + return `(${range}(\\,${range})*)`; |
| 20 | +} |
| 21 | + |
| 22 | +function slashRegex(values: string): string { |
| 23 | + const range = rangeRegex(values); |
| 24 | + return `((\\*|${range}|${values})\\/${numbers})`; |
| 25 | +} |
| 26 | + |
| 27 | +function listSlashRegex(values: string): string { |
| 28 | + const slash = slashRegex(values); |
| 29 | + const slashOrRange = `(${slash}|${rangeRegex(values)})`; |
| 30 | + return `(${slashOrRange}(\\,${slashOrRange})*)`; |
| 31 | +} |
| 32 | + |
| 33 | +function commonRegex(values: string): string { |
| 34 | + return `(${listRangeRegex(values)}|\\*|${listSlashRegex(values)})`; |
| 35 | +} |
| 36 | + |
| 37 | +export function minuteRegex(): string { |
| 38 | + return `^(${commonRegex(minuteExp)})$`; |
| 39 | +} |
| 40 | + |
| 41 | +export function hourRegex(): string { |
| 42 | + return `^(${commonRegex(hourExp)})$`; |
| 43 | +} |
| 44 | + |
| 45 | +export function dayOfMonthRegex(): string { |
| 46 | + return `^(${commonRegex(dayOfMonthExp)}|\\?|L|LW|${dayOfMonthExp}W)$`; |
| 47 | +} |
| 48 | + |
| 49 | +export function monthRegex(): string { |
| 50 | + return `^(${commonRegex(monthExp)})$`; |
| 51 | +} |
| 52 | + |
| 53 | +export function dayOfWeekRegex(): string { |
| 54 | + const rangeList = listRangeRegex(dayOfWeekExp); |
| 55 | + return `^(${rangeList}|\\*|\\?|${dayOfWeekExp}L|L|L-[1-7]|${dayOfWeekHash()})$`; |
| 56 | +} |
| 57 | + |
| 58 | +export function yearRegex(): string { |
| 59 | + return `^(${commonRegex(yearExp)})$`; |
| 60 | +} |
0 commit comments