MCPcopy
hub / github.com/grafana/tempo / parseTime

Function parseTime

cmd/tempo-cli/shared.go:212–224  ·  view source on GitHub ↗

parseTime parses a time string that can be: - relative: "now", "now-1h", "now-30m", "now-3h30m" - RFC3339: "2024-01-01T00:00:00Z"

(s string)

Source from the content-addressed store, hash-verified

210// - relative: "now", "now-1h", "now-30m", "now-3h30m"
211// - RFC3339: "2024-01-01T00:00:00Z"
212func parseTime(s string) (time.Time, error) {
213 s = strings.TrimSpace(s)
214
215 if strings.HasPrefix(s, "now") {
216 return parseRelativeTime(s)
217 }
218
219 if t, err := time.Parse(time.RFC3339, s); err == nil {
220 return t, nil
221 }
222
223 return time.Time{}, fmt.Errorf("failed to parse time: %q use relative (now, now-1h) or absolute RFC3339 (2006-01-02T15:04:05Z07:00) format", s)
224}
225
226func parseRelativeTime(s string) (time.Time, error) {
227 now := time.Now()

Callers 6

TestParseTimeFunction · 0.85
RunMethod · 0.85
RunMethod · 0.85
RunMethod · 0.85
RunMethod · 0.85
RunMethod · 0.85

Calls 2

parseRelativeTimeFunction · 0.85
ParseMethod · 0.65

Tested by 1

TestParseTimeFunction · 0.68