Files
zeekayandHanzo Dev b726a55cab cd: internalize the five argoproj/pkg utilities, drop the dependency
github.com/argoproj/pkg/v2 was one of two live argoproj dependencies. It is
11 files and 176K total, and we used five packages from it: grpc/http,
kubeclientmetrics, stats, sync, time.

Vendored into util/vendored/ and the dependency dropped from go.mod, so the
gRPC surface (2 references, in grpc-http/forwarders.go) is now ours to remove
on our own schedule rather than upstream's. Kubernetes client-go pulls gRPC
transitively regardless, so this is isolation — a realistic first step — not
a claim that gRPC is gone.

Internalized rather than forked to a shared repo because the only other
consumer, hanzo/gitops, has zero live deployments and zero dependents. A
second repo would be a second thing to version for one caller.

NOTICE carries the Apache-2.0 attribution. go build ./... exit 0.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-28 16:08:34 -07:00

47 lines
1.0 KiB
Go

package time
import (
"fmt"
"log"
"regexp"
"strconv"
"time"
)
var durationRegex = regexp.MustCompile(`^(\d+)([smhd])$`)
// ParseDuration parses a duration string and returns the time.Duration
func ParseDuration(duration string) (*time.Duration, error) {
matches := durationRegex.FindStringSubmatch(duration)
if len(matches) != 3 {
return nil, fmt.Errorf("invalid since format '%s', expected format <duration><unit> (e.g. 3h)", duration)
}
amount, err := strconv.ParseInt(matches[1], 10, 64)
if err != nil {
log.Fatal(err)
}
var unit time.Duration
switch matches[2] {
case "s":
unit = time.Second
case "m":
unit = time.Minute
case "h":
unit = time.Hour
case "d":
unit = time.Hour * 24
}
dur := unit * time.Duration(amount)
return &dur, nil
}
// ParseSince parses a duration string and returns a time.Time in history relative to current time
func ParseSince(duration string) (*time.Time, error) {
dur, err := ParseDuration(duration)
if err != nil {
return nil, err
}
since := time.Now().UTC().Add(-*dur)
return &since, nil
}