IsWeeklyCron checks if a cron expression represents a weekly schedule at a fixed time (e.g., "0 0 * * 1", "30 14 * * 5", etc.)
(cron string)
| 88 | // IsWeeklyCron checks if a cron expression represents a weekly schedule at a fixed time |
| 89 | // (e.g., "0 0 * * 1", "30 14 * * 5", etc.) |
| 90 | func IsWeeklyCron(cron string) bool { |
| 91 | fields := strings.Fields(cron) |
| 92 | if len(fields) != 5 { |
| 93 | return false |
| 94 | } |
| 95 | // Weekly pattern: minute hour * * DOW |
| 96 | // The minute and hour must be specific values (numbers), not wildcards |
| 97 | // The day-of-month (3rd field) and month (4th field) must be "*" |
| 98 | // The day-of-week (5th field) must be a specific day (0-6) |
| 99 | |
| 100 | // Check if minute and hour are numeric (not wildcards) |
| 101 | minute := fields[0] |
| 102 | hour := fields[1] |
| 103 | |
| 104 | // Minute and hour should be digits only (no *, /, -, ,) |
| 105 | for _, ch := range minute { |
| 106 | if ch < '0' || ch > '9' { |
| 107 | return false |
| 108 | } |
| 109 | } |
| 110 | for _, ch := range hour { |
| 111 | if ch < '0' || ch > '9' { |
| 112 | return false |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | // Check day-of-month and month are wildcards |
| 117 | if fields[2] != "*" || fields[3] != "*" { |
| 118 | return false |
| 119 | } |
| 120 | |
| 121 | // Check day-of-week is a specific day (0-6) |
| 122 | dow := fields[4] |
| 123 | for _, ch := range dow { |
| 124 | if ch < '0' || ch > '6' { |
| 125 | return false |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | cronDetectionLog.Printf("Cron expression classified as weekly: %q (minute=%s, hour=%s, dow=%s)", cron, minute, hour, dow) |
| 130 | return true |
| 131 | } |
| 132 | |
| 133 | // IsFuzzyCron checks if a cron expression is a fuzzy schedule placeholder |
| 134 | func IsFuzzyCron(cron string) bool { |