MCPcopy Create free account
hub / github.com/Facets-cloud/flow / ParseSince

Function ParseSince

internal/stats/report.go:224–240  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

222// ParseSince converts a --since value to a lower-bound time. "all"/"" → zero
223// (no bound); "<N>d" → now minus N days; otherwise RFC3339.
224func 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
242func windowLabel(since time.Time) string {
243 if since.IsZero() {

Callers 2

cmdStatsFunction · 0.92
TestParseSinceFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestParseSinceFunction · 0.68