MCPcopy Create free account
hub / github.com/devfeel/dottask / parseExpress

Function parseExpress

express.go:69–189  ·  view source on GitHub ↗

* parse express maybe: "*" "*\/5" "1,2,3,5-8" */

(express, expressType string)

Source from the content-addressed store, hash-verified

67"*" "*\/5" "1,2,3,5-8"
68*/
69func parseExpress(express, expressType string) (times *ExpressSet) {
70 V_Max := 0
71 V_Min := 0
72
73 switch expressType {
74 case ExpressType_WeekDay:
75 V_Max = Max_WeekDay
76 V_Min = Min_WeekDay
77 case ExpressType_Month:
78 V_Max = Max_Month
79 V_Min = Min_Month
80 case ExpressType_Day:
81 V_Max = Max_Day
82 V_Min = Min_Day
83 case ExpressType_Hour:
84 V_Max = Max_Hour
85 V_Min = Min_Hour
86 case ExpressType_Minute:
87 V_Max = Max_Minute
88 V_Min = Min_Minute
89 case ExpressType_Second:
90 V_Max = Max_Second
91 V_Min = Min_Second
92 default:
93 return nil
94 }
95
96 times = &ExpressSet{timeMap: make(map[int]int), expressType: expressType, rawExpress: express}
97
98 //if contains "/", reset frequency
99 frequency := 1
100 var err error
101 if strings.Contains(express, "/") {
102 frequency, err = strconv.Atoi(subString(express, strings.Index(express, "/")+1, -1))
103 if err != nil {
104 return nil
105 }
106 express = subString(express, 0, strings.Index(express, "/"))
107 }
108
109 //if express like "*" or "*/5"
110 if express == "*" {
111 for i := V_Min; i <= V_Max; i = i + frequency {
112 times.timeMap[i] = i
113 }
114 } else {
115 //if express like "1,2,4,12-20" or "12-2"
116 //tops:if parse int failed, will be ignore
117 tmpVals := strings.Split(express, ",")
118 for i := 0; i < len(tmpVals); i++ {
119 val := tmpVals[i]
120 if val == "" {
121 continue
122 }
123 //if not exists "-", parse int and join to times
124 if !strings.Contains(val, "-") {
125 atoi, errAtoi := strconv.Atoi(val)
126 if errAtoi == nil {

Callers 3

TestParseExpressFunction · 0.85
ResetMethod · 0.85
NewCronTaskFunction · 0.85

Calls 1

subStringFunction · 0.85

Tested by 1

TestParseExpressFunction · 0.68