MCPcopy
hub / github.com/larksuite/cli / parseTimeRange

Function parseTimeRange

shortcuts/vc/vc_search.go:40–70  ·  view source on GitHub ↗

parseTimeRange validates --start/--end and returns RFC3339 formatted strings.

(runtime *common.RuntimeContext)

Source from the content-addressed store, hash-verified

38
39// parseTimeRange validates --start/--end and returns RFC3339 formatted strings.
40func 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.
73func uniqueIDs(ids []string) []string {

Calls 4

NewValidationErrorFunction · 0.92
WithParamMethod · 0.80
toRFC3339Function · 0.70
StrMethod · 0.65