File tree Expand file tree Collapse file tree 3 files changed +14
-1
lines changed Expand file tree Collapse file tree 3 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ require (
1313 github.com/pion/udp v0.1.4
1414 github.com/spf13/pflag v1.0.5
1515 github.com/stretchr/testify v1.8.4
16+ github.com/xhit/go-str2duration/v2 v2.1.0
1617 golang.org/x/crypto v0.19.0
1718 golang.org/x/exp v0.0.0-20240213143201-ec583247a57a
1819 golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028
Original file line number Diff line number Diff line change @@ -81,6 +81,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
8181github.com/stretchr/testify v1.8.1 /go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4 =
8282github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk =
8383github.com/stretchr/testify v1.8.4 /go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo =
84+ github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc =
85+ github.com/xhit/go-str2duration/v2 v2.1.0 /go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU =
8486github.com/yuin/goldmark v1.4.13 /go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY =
8587go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs =
8688go.opentelemetry.io/otel v1.19.0 /go.mod h1:i0QyjOq3UPoTzff0PJB2N66fb4S0+rSbSB15/oyH9fY =
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import (
1313 "time"
1414
1515 "github.com/spf13/pflag"
16+ str2duration "github.com/xhit/go-str2duration/v2"
1617 "golang.org/x/xerrors"
1718 "gopkg.in/yaml.v3"
1819)
@@ -262,7 +263,16 @@ func DurationOf(d *time.Duration) *Duration {
262263}
263264
264265func (d * Duration ) Set (v string ) error {
265- dd , err := time .ParseDuration (v )
266+ // Try [str2duration.ParseDuration] first, which supports days and weeks.
267+ // If it fails, fall back to [time.ParseDuration] for backward compatibility.
268+ dd , err := str2duration .ParseDuration (v )
269+ if err == nil {
270+ * d = Duration (dd )
271+ return nil
272+ }
273+
274+ // Fallback to standard [time.ParseDuration].
275+ dd , err = time .ParseDuration (v )
266276 * d = Duration (dd )
267277 return err
268278}
You can’t perform that action at this time.
0 commit comments