Some checks failed
CI / init (push) Has been cancelled
CI / Frontend node 18.16.0 (push) Has been cancelled
CI / Backend go (1.22) (push) Has been cancelled
CI / devops-test (1.22, 18.16.0) (push) Has been cancelled
CI / release-pr (push) Has been cancelled
CI / release-please (push) Has been cancelled
CI / devops-prod (1.22, 18.x) (push) Has been cancelled
CI / docker (push) Has been cancelled
30 lines
540 B
Go
30 lines
540 B
Go
package utils
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
func ParseDuration(d string) (time.Duration, error) {
|
|
d = strings.TrimSpace(d)
|
|
dr, err := time.ParseDuration(d)
|
|
if err == nil {
|
|
return dr, nil
|
|
}
|
|
if strings.Contains(d, "d") {
|
|
index := strings.Index(d, "d")
|
|
|
|
hour, _ := strconv.Atoi(d[:index])
|
|
dr = time.Hour * 24 * time.Duration(hour)
|
|
ndr, err := time.ParseDuration(d[index+1:])
|
|
if err != nil {
|
|
return dr, nil
|
|
}
|
|
return dr + ndr, nil
|
|
}
|
|
|
|
dv, err := strconv.ParseInt(d, 10, 64)
|
|
return time.Duration(dv), err
|
|
}
|