-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
48 lines (40 loc) · 1.2 KB
/
main.go
File metadata and controls
48 lines (40 loc) · 1.2 KB
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
package main
import (
"fmt"
"github.com/corn-parser/util"
"os"
"strings"
)
func main() {
if len(os.Args) != 2 {
fmt.Println("Usage: cron-parser \"<cron string>\"")
return
}
cron := os.Args[1]
if !util.ValidCornParser(cron) {
fmt.Println("Invalid cron string format.")
return
}
parts := strings.Fields(cron)
if len(parts) != 6 {
fmt.Printf("Invalid number of parts present expected 6 found %d\n", len(parts))
return
}
minuteField := parts[0]
hourField := parts[1]
dayOfMonthField := parts[2]
monthField := parts[3]
dayOfWeekField := parts[4]
command := parts[5]
minutes := util.ExpandField(minuteField, 0, 59)
hours := util.ExpandField(hourField, 0, 23)
daysOfMonth := util.ExpandField(dayOfMonthField, 1, 31)
months := util.ExpandField(monthField, 1, 12)
daysOfWeek := util.ExpandField(dayOfWeekField, 0, 6)
fmt.Printf("%-14s%s\n", "minute", strings.Join(minutes, " "))
fmt.Printf("%-14s%s\n", "hour", strings.Join(hours, " "))
fmt.Printf("%-14s%s\n", "day of month", strings.Join(daysOfMonth, " "))
fmt.Printf("%-14s%s\n", "month", strings.Join(months, " "))
fmt.Printf("%-14s%s\n", "day of week", strings.Join(daysOfWeek, " "))
fmt.Printf("%-14s%s\n", "command", command)
}