MCPcopy
hub / github.com/prometheus/prometheus / parseTime

Function parseTime

web/api/v1/api.go:2265–2286  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

2263}
2264
2265func parseTime(s string) (time.Time, error) {
2266 if t, err := strconv.ParseFloat(s, 64); err == nil {
2267 s, ns := math.Modf(t)
2268 ns = math.Round(ns*1000) / 1000
2269 return time.Unix(int64(s), int64(ns*float64(time.Second))).UTC(), nil
2270 }
2271 if t, err := time.Parse(time.RFC3339Nano, s); err == nil {
2272 return t, nil
2273 }
2274
2275 // Stdlib's time parser can only handle 4 digit years. As a workaround until
2276 // that is fixed we want to at least support our own boundary times.
2277 // Context: https://github.com/prometheus/client_golang/issues/614
2278 // Upstream issue: https://github.com/golang/go/issues/20555
2279 switch s {
2280 case minTimeFormatted:
2281 return MinTime, nil
2282 case maxTimeFormatted:
2283 return MaxTime, nil
2284 }
2285 return time.Time{}, fmt.Errorf("cannot parse %q to a valid timestamp", s)
2286}
2287
2288func parseDuration(s string) (time.Duration, error) {
2289 if d, err := strconv.ParseFloat(s, 64); err == nil {

Callers 4

queryRangeMethod · 0.70
parseTimeParamFunction · 0.70
TestParseTimeParamFunction · 0.70
TestParseTimeFunction · 0.70

Calls 1

ParseMethod · 0.65

Tested by 2

TestParseTimeParamFunction · 0.56
TestParseTimeFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…