init project

This commit is contained in:
2025-04-09 12:17:33 +08:00
parent 6840d5d5e3
commit f6622a4e98
392 changed files with 55744 additions and 3 deletions

29
utils/human_duration.go Normal file
View File

@@ -0,0 +1,29 @@
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
}