From 8ea02d0b6033b6ffdc68d38f3276410f4e2e8eb9 Mon Sep 17 00:00:00 2001 From: Jakub Guzik Date: Thu, 18 Mar 2021 00:01:50 +0100 Subject: network prune filters for http compat and libpod api Signed-off-by: Jakub Guzik --- pkg/util/filters.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 pkg/util/filters.go (limited to 'pkg/util') diff --git a/pkg/util/filters.go b/pkg/util/filters.go new file mode 100644 index 000000000..bf16f89e3 --- /dev/null +++ b/pkg/util/filters.go @@ -0,0 +1,25 @@ +package util + +import ( + "time" + + "github.com/containers/podman/v3/pkg/timetype" + "github.com/pkg/errors" +) + +// ComputeUntilTimestamp extracts unitil timestamp from filters +func ComputeUntilTimestamp(filter string, filterValues []string) (time.Time, error) { + invalid := time.Time{} + if len(filterValues) != 1 { + return invalid, errors.Errorf("specify exactly one timestamp for %s", filter) + } + ts, err := timetype.GetTimestamp(filterValues[0], time.Now()) + if err != nil { + return invalid, err + } + seconds, nanoseconds, err := timetype.ParseTimestamps(ts, 0) + if err != nil { + return invalid, err + } + return time.Unix(seconds, nanoseconds), nil +} -- cgit v1.2.3-54-g00ecf