(s string)
| 2263 | } |
| 2264 | |
| 2265 | func 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 | |
| 2288 | func parseDuration(s string) (time.Duration, error) { |
| 2289 | if d, err := strconv.ParseFloat(s, 64); err == nil { |
searching dependent graphs…