{"record":{"id":"e0b11ee39a3d6b1b","repo":"thanos-io/thanos","slug":"invalid-time-value-for-s","errorCode":null,"errorMessage":"Invalid time value for '%s'","messagePattern":"Invalid time value for '(.+?)'","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"pkg/api/query/v1.go","lineNumber":1585,"sourceCode":"\t}\n\tif end.Before(start) {\n\t\treturn time.Time{}, time.Time{}, &api.ApiError{\n\t\t\tTyp: api.ErrorBadData,\n\t\t\tErr: errors.New(\"end timestamp must not be before start time\"),\n\t\t}\n\t}\n\n\treturn start, end, nil\n}\n\nfunc parseTimeParam(r *http.Request, paramName string, defaultValue time.Time) (time.Time, error) {\n\tval := r.FormValue(paramName)\n\tif val == \"\" {\n\t\treturn defaultValue, nil\n\t}\n\tresult, err := parseTime(val)\n\tif err != nil {\n\t\treturn time.Time{}, errors.Wrapf(err, \"Invalid time value for '%s'\", paramName)\n\t}\n\treturn result, nil\n}\n\nfunc parseTime(s string) (time.Time, error) {\n\tif t, err := strconv.ParseFloat(s, 64); err == nil {\n\t\ts, ns := math.Modf(t)\n\t\tns = math.Round(ns*1000) / 1000\n\t\treturn time.Unix(int64(s), int64(ns*float64(time.Second))), nil\n\t}\n\tif t, err := time.Parse(time.RFC3339Nano, s); err == nil {\n\t\treturn t, nil\n\t}\n\treturn time.Time{}, errors.Errorf(\"cannot parse %q to a valid timestamp\", s)\n}\n\nfunc parseDuration(s string) (time.Duration, error) {\n\tif d, err := strconv.ParseFloat(s, 64); err == nil {","sourceCodeStart":1567,"sourceCodeEnd":1603,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/api/query/v1.go#L1567-L1603","documentation":"This error is produced when a time parameter (e.g. 'start', 'end', 'time') on query/metadata endpoints cannot be parsed by parseTime, and is wrapped with the parameter name via errors.Wrapf. parseTime accepts unix floats (seconds, fractional seconds allowed) and RFC3339Nano strings; anything else fails, surfacing ErrorBadData (HTTP 400).","triggerScenarios":"GET /api/v1/query?query=up&time=now, or start=2024/01/02, or any non-numeric, non-RFC3339 value for a named time parameter.","commonSituations":"Passing human-friendly strings like 'now', '1h ago', or local-format dates (dd/mm/yyyy), forgetting URL-encoding so '+' in RFC3339 becomes a space, or passing millisecond epochs where seconds are expected.","solutions":["Send a unix timestamp in seconds (float ok) or an RFC3339Nano string like 2024-01-02T15:04:05Z.","Encode the value in the URL (RFC3339 '+' must be %2B in query strings).","Convert 'now' to an explicit timestamp client-side before calling.","Use milliseconds correctly: divide epoch-millis by 1000 for seconds."],"exampleFix":"// before\ncurl 'http://query:9090/api/v1/query?query=up&time=2024-01-02 15:04:05'\n// after\ncurl 'http://query:9090/api/v1/query?query=up&time=2024-01-02T15%3A04%3A05Z'","handlingStrategy":"validation","validationCode":"function toApiTime(v) {\n  if (v instanceof Date) return v.toISOString();\n  const n = Number(v);\n  if (Number.isFinite(n)) return String(n); // unix seconds (float ok)\n  if (!Number.isNaN(Date.parse(v))) return new Date(v).toISOString();\n  throw new Error(`invalid time: ${v}`);\n}","typeGuard":null,"tryCatchPattern":"try { const t = toApiTime(raw); } catch (e) { /* fix or drop the param before calling API */ }","preventionTips":["Always send unix seconds or RFC3339Nano, never locale strings or 'now'.","URL-encode timestamps ('+' as %2B).","Convert epoch-milliseconds to seconds before sending."],"tags":["api","validation","time","parsing"],"backgroundTag":"invalid-date-format","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}