parseTimeRange validates --start/--end and returns RFC3339 formatted strings.
(runtime *common.RuntimeContext)
| 38 | |
| 39 | // parseTimeRange validates --start/--end and returns RFC3339 formatted strings. |
| 40 | func parseTimeRange(runtime *common.RuntimeContext) (string, string, error) { |
| 41 | start := strings.TrimSpace(runtime.Str("start")) |
| 42 | end := strings.TrimSpace(runtime.Str("end")) |
| 43 | if start == "" && end == "" { |
| 44 | return "", "", nil |
| 45 | } |
| 46 | var startTime, endTime string |
| 47 | if start != "" { |
| 48 | parsed, err := toRFC3339(start) |
| 49 | if err != nil { |
| 50 | return "", "", errs.NewValidationError(errs.SubtypeInvalidArgument, "--start: %v", err).WithParam("--start") |
| 51 | } |
| 52 | startTime = parsed |
| 53 | } |
| 54 | if end != "" { |
| 55 | parsed, err := toRFC3339(end, "end") |
| 56 | if err != nil { |
| 57 | return "", "", errs.NewValidationError(errs.SubtypeInvalidArgument, "--end: %v", err).WithParam("--end") |
| 58 | } |
| 59 | endTime = parsed |
| 60 | } |
| 61 | // validate start <= end |
| 62 | if startTime != "" && endTime != "" { |
| 63 | st, _ := time.Parse(time.RFC3339, startTime) |
| 64 | et, _ := time.Parse(time.RFC3339, endTime) |
| 65 | if st.After(et) { |
| 66 | return "", "", errs.NewValidationError(errs.SubtypeInvalidArgument, "--start (%s) is after --end (%s)", start, end).WithParam("--start") |
| 67 | } |
| 68 | } |
| 69 | return startTime, endTime, nil |
| 70 | } |
| 71 | |
| 72 | // uniqueIDs deduplicates a string slice while preserving order. |
| 73 | func uniqueIDs(ids []string) []string { |