ParseTime parses the string into an int64, milliseconds since epoch.
(s string)
| 45 | |
| 46 | // ParseTime parses the string into an int64, milliseconds since epoch. |
| 47 | func 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. |
| 61 | func ParseTimeParam(r *http.Request, paramName string, defaultValue int64) (int64, error) { |