优化结构

This commit is contained in:
Yvan
2026-08-23 07:48:02 +08:00
parent 40632c5756
commit 7a9a738c6a
15 changed files with 590 additions and 83 deletions
+13 -3
View File
@@ -274,12 +274,22 @@ func parseCompatibleDuration(raw string) (time.Duration, error) {
return value, nil
}
if index := strings.Index(raw, "d"); index >= 0 {
days, _ := strconv.Atoi(raw[:index])
value := time.Duration(days) * 24 * time.Hour
remainder, err := time.ParseDuration(raw[index+1:])
if index == 0 {
return 0, strconv.ErrSyntax
}
days, err := strconv.Atoi(raw[:index])
if err != nil {
return 0, err
}
value := time.Duration(days) * 24 * time.Hour
remainderText := strings.TrimSpace(raw[index+1:])
if remainderText == "" {
return value, nil
}
remainder, err := time.ParseDuration(remainderText)
if err != nil {
return 0, err
}
return value + remainder, nil
}
nanoseconds, err := strconv.ParseInt(raw, 10, 64)