MCPcopy Create free account
hub / github.com/github/gh-aw / ParseSchedule

Function ParseSchedule

pkg/parser/schedule_parser.go:27–59  ·  view source on GitHub ↗

ParseSchedule converts a human-friendly schedule expression into a cron expression Returns the cron expression and the original friendly format for comments

(input string)

Source from the content-addressed store, hash-verified

25// ParseSchedule converts a human-friendly schedule expression into a cron expression
26// Returns the cron expression and the original friendly format for comments
27func ParseSchedule(input string) (cron string, original string, err error) {
28 scheduleLog.Printf("Parsing schedule expression: %s", input)
29 input = strings.TrimSpace(input)
30 if input == "" {
31 return "", "", errors.New("schedule expression cannot be empty")
32 }
33
34 // If it's already a cron expression (5 fields separated by spaces), return as-is
35 if IsCronExpression(input) {
36 scheduleLog.Printf("Input is already a valid cron expression: %s", input)
37 return input, "", nil
38 }
39
40 parser := &ScheduleParser{
41 input: input,
42 }
43
44 // Tokenize the input
45 if err := parser.tokenize(); err != nil {
46 scheduleLog.Printf("Tokenization failed: %s", err)
47 return "", "", err
48 }
49
50 // Parse the tokens
51 cronExpr, err := parser.parse()
52 if err != nil {
53 scheduleLog.Printf("Parsing failed: %s", err)
54 return "", "", err
55 }
56
57 scheduleLog.Printf("Successfully parsed schedule to cron: %s", cronExpr)
58 return cronExpr, input, nil
59}
60
61// tokenize breaks the input into tokens
62func (p *ScheduleParser) tokenize() error {

Callers 5

FuzzScheduleParserFunction · 0.85
TestParseScheduleFunction · 0.85

Calls 4

tokenizeMethod · 0.95
parseMethod · 0.95
IsCronExpressionFunction · 0.85
PrintfMethod · 0.45

Tested by 3

FuzzScheduleParserFunction · 0.68
TestParseScheduleFunction · 0.68