MCPcopy Index your code
hub / github.com/google/mangle / parseDuration

Function parseDuration

parse/parse.go:921–935  ·  view source on GitHub ↗

parseDuration parses a duration string like "7d", "24h", "30m", "1s", "500ms". parseDuration parses a Go-style duration string. Supported units: h (hours), m (minutes), s (seconds), ms (milliseconds), us/µs (microseconds), ns (nanoseconds) Examples: "1h30m", "500ms", "2h45m30s" Note: Days ('d') are

(s string)

Source from the content-addressed store, hash-verified

919// Examples: "1h30m", "500ms", "2h45m30s"
920// Note: Days ('d') are supported by converting to hours (24h).
921func parseDuration(s string) (time.Duration, error) {
922 if s == "" {
923 return 0, fmt.Errorf("empty duration string")
924 }
925 // Handle days manually since time.ParseDuration doesn't support 'd'
926 if strings.HasSuffix(s, "d") {
927 daysStr := strings.TrimSuffix(s, "d")
928 days, err := strconv.ParseInt(daysStr, 10, 64)
929 if err != nil {
930 return 0, fmt.Errorf("invalid duration days: %v", err)
931 }
932 return time.Duration(days) * 24 * time.Hour, nil
933 }
934 return time.ParseDuration(s)
935}

Callers 2

VisitTemporalBoundMethod · 0.85
TestParseDurationFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestParseDurationFunction · 0.68