parseTime parses a time string that can be: - relative: "now", "now-1h", "now-30m", "now-3h30m" - RFC3339: "2024-01-01T00:00:00Z"
(s string)
| 210 | // - relative: "now", "now-1h", "now-30m", "now-3h30m" |
| 211 | // - RFC3339: "2024-01-01T00:00:00Z" |
| 212 | func parseTime(s string) (time.Time, error) { |
| 213 | s = strings.TrimSpace(s) |
| 214 | |
| 215 | if strings.HasPrefix(s, "now") { |
| 216 | return parseRelativeTime(s) |
| 217 | } |
| 218 | |
| 219 | if t, err := time.Parse(time.RFC3339, s); err == nil { |
| 220 | return t, nil |
| 221 | } |
| 222 | |
| 223 | return time.Time{}, fmt.Errorf("failed to parse time: %q use relative (now, now-1h) or absolute RFC3339 (2006-01-02T15:04:05Z07:00) format", s) |
| 224 | } |
| 225 | |
| 226 | func parseRelativeTime(s string) (time.Time, error) { |
| 227 | now := time.Now() |