| 152 | } |
| 153 | |
| 154 | func 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 | |
| 186 | func parseField(value string, fieldType fieldType) (*cronFieldBits, error) { |
| 187 | if len(value) == 0 { |