improve gtime.ParseDuration

This commit is contained in:
john
2020-07-29 11:44:58 +08:00
parent 91cd34b26a
commit c4b28b0bc4
2 changed files with 6 additions and 1 deletions

View File

@ -404,7 +404,7 @@ func ParseDuration(s string) (time.Duration, error) {
}
return time.Duration(v), nil
}
match, err := gregex.MatchString(`^([\-\d]+)[dD](.+)$`, s)
match, err := gregex.MatchString(`^([\-\d]+)[dD](.*)$`, s)
if err != nil {
return 0, err
}

View File

@ -221,6 +221,11 @@ func Test_ConvertZone(t *testing.T) {
}
func Test_ParseDuration(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
d, err := gtime.ParseDuration("1d")
t.Assert(err, nil)
t.Assert(d.String(), "24h0m0s")
})
gtest.C(t, func(t *gtest.T) {
d, err := gtime.ParseDuration("1d2h3m")
t.Assert(err, nil)