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

Function ParseDurationMs

pkg/util/time.go:230–242  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

228}
229
230func ParseDurationMs(s string) (int64, error) {
231 if d, err := strconv.ParseFloat(s, 64); err == nil {
232 ts := d * float64(time.Second/time.Millisecond)
233 if ts > float64(math.MaxInt64) || ts < float64(math.MinInt64) {
234 return 0, httpgrpc.Errorf(http.StatusBadRequest, "cannot parse %q to a valid duration. It overflows int64", s)
235 }
236 return int64(ts), nil
237 }
238 if d, err := model.ParseDuration(s); err == nil {
239 return int64(d) / int64(time.Millisecond/time.Nanosecond), nil
240 }
241 return 0, httpgrpc.Errorf(http.StatusBadRequest, "cannot parse %q to a valid duration", s)
242}
243
244func DurationMilliseconds(d time.Duration) int64 {
245 return int64(d / (time.Millisecond / time.Nanosecond))

Callers 5

RangeQueryHandlerMethod · 0.92
InstantQueryHandlerMethod · 0.92
extractQueryOptsFunction · 0.92
isWithinQueryStepLimitFunction · 0.92
DecodeRequestMethod · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected