MCPcopy Create free account
hub / github.com/codnect/chrono / ParseCronExpression

Function ParseCronExpression

cron.go:154–184  ·  view source on GitHub ↗
(expression string)

Source from the content-addressed store, hash-verified

152}
153
154func ParseCronExpression(expression string) (*CronExpression, error) {
155 if len(expression) == 0 {
156 return nil, errors.New("cron expression must not be empty")
157 }
158
159 fields := strings.Fields(expression)
160
161 if len(fields) != 6 {
162 return nil, fmt.Errorf("cron expression must consist of 6 fields : found %d in \"%s\"", len(fields), expression)
163 }
164
165 cronExpression := newCronExpression()
166
167 for index, cronFieldType := range cronFieldTypes {
168 value, err := parseField(fields[index], cronFieldType)
169
170 if err != nil {
171 return nil, err
172 }
173
174 if cronFieldType.Field == cronFieldDayOfWeek && value.Bits&1<<0 != 0 {
175 value.Bits |= 1 << 7
176 temp := ^(1 << 0)
177 value.Bits &= uint64(temp)
178 }
179
180 cronExpression.fields = append(cronExpression.fields, value)
181 }
182
183 return cronExpression, nil
184}
185
186func parseField(value string, fieldType fieldType) (*cronFieldBits, error) {
187 if len(value) == 0 {

Callers 3

CreateCronTriggerFunction · 0.85

Calls 2

newCronExpressionFunction · 0.85
parseFieldFunction · 0.85

Tested by 2