diff --git a/web/api/v1/api.go b/web/api/v1/api.go index 9c54f5973..0bd5096ff 100644 --- a/web/api/v1/api.go +++ b/web/api/v1/api.go @@ -1150,6 +1150,7 @@ func (api *API) respondError(w http.ResponseWriter, apiErr *apiError, data inter func parseTime(s string) (time.Time, error) { if t, err := strconv.ParseFloat(s, 64); err == nil { s, ns := math.Modf(t) + ns = math.Round(ns*1000) / 1000 return time.Unix(int64(s), int64(ns*float64(time.Second))), nil } if t, err := time.Parse(time.RFC3339Nano, s); err == nil { diff --git a/web/api/v1/api_test.go b/web/api/v1/api_test.go index 3e97f6a82..bdc6c2d64 100644 --- a/web/api/v1/api_test.go +++ b/web/api/v1/api_test.go @@ -1318,6 +1318,10 @@ func TestParseTime(t *testing.T) { }, { input: "2015-06-03T14:21:58.555+01:00", result: ts, + }, { + // Test float rounding. + input: "1543578564.705", + result: time.Unix(1543578564, 705*1e6), }, }