ParseSince converts a --since value to a lower-bound time. "all"/"" → zero (no bound); " d" → now minus N days; otherwise RFC3339.
(s string, now time.Time)
| 222 | // ParseSince converts a --since value to a lower-bound time. "all"/"" → zero |
| 223 | // (no bound); "<N>d" → now minus N days; otherwise RFC3339. |
| 224 | func ParseSince(s string, now time.Time) (time.Time, error) { |
| 225 | if s == "" || s == "all" { |
| 226 | return time.Time{}, nil |
| 227 | } |
| 228 | if strings.HasSuffix(s, "d") { |
| 229 | n, err := strconv.Atoi(strings.TrimSuffix(s, "d")) |
| 230 | if err != nil || n < 0 { |
| 231 | return time.Time{}, fmt.Errorf("invalid --since %q", s) |
| 232 | } |
| 233 | return now.AddDate(0, 0, -n), nil |
| 234 | } |
| 235 | t, err := time.Parse(time.RFC3339, s) |
| 236 | if err != nil { |
| 237 | return time.Time{}, fmt.Errorf("invalid --since %q (use all, <N>d, or RFC3339)", s) |
| 238 | } |
| 239 | return t, nil |
| 240 | } |
| 241 | |
| 242 | func windowLabel(since time.Time) string { |
| 243 | if since.IsZero() { |
no outgoing calls