MCPcopy Index your code
hub / github.com/cortexproject/cortex / ParseTime

Function ParseTime

pkg/util/time.go:47–58  ·  view source on GitHub ↗

ParseTime parses the string into an int64, milliseconds since epoch.

(s string)

Source from the content-addressed store, hash-verified

45
46// ParseTime parses the string into an int64, milliseconds since epoch.
47func ParseTime(s string) (int64, error) {
48 if t, err := strconv.ParseFloat(s, 64); err == nil {
49 s, ns := math.Modf(t)
50 ns = math.Round(ns*1000) / 1000
51 tm := time.Unix(int64(s), int64(ns*float64(time.Second)))
52 return TimeToMillis(tm), nil
53 }
54 if t, err := time.Parse(time.RFC3339Nano, s); err == nil {
55 return TimeToMillis(t), nil
56 }
57 return 0, httpgrpc.Errorf(http.StatusBadRequest, "cannot parse %q to a valid timestamp", s)
58}
59
60// ParseTimeParam parses the time request parameter into an int64, milliseconds since epoch.
61func ParseTimeParam(r *http.Request, paramName string, defaultValue int64) (int64, error) {

Callers 6

RangeQueryHandlerMethod · 0.92
DecodeRequestMethod · 0.92
ParseTimeParamFunction · 0.85
FindMinMaxTimeFunction · 0.85
TestParseTimeFunction · 0.85

Calls 2

TimeToMillisFunction · 0.85
ParseMethod · 0.80

Tested by 1

TestParseTimeFunction · 0.68