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

Function parseRelativeTime

cmd/tempo-cli/shared.go:226–246  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

224}
225
226func parseRelativeTime(s string) (time.Time, error) {
227 now := time.Now()
228 s = strings.TrimSpace(s)
229
230 if s == "now" {
231 return now, nil
232 }
233
234 // expect "now-<duration>"
235 if !strings.HasPrefix(s, "now-") {
236 return time.Time{}, fmt.Errorf("invalid relative time %q: expected format like now-1h", s)
237 }
238
239 durStr := s[len("now-"):]
240 d, err := model.ParseDuration(durStr)
241 if err != nil {
242 return time.Time{}, fmt.Errorf("failed to parse duration %q: %w", durStr, err)
243 }
244
245 return now.Add(-time.Duration(d)), nil
246}

Callers 1

parseTimeFunction · 0.85

Calls 3

DurationMethod · 0.80
NowMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected