This commit is contained in:
oneao committed 2026-03-04 17:30:05 +08:00
1 parent 46106d0c76
commit 34240d2e16
36 files changed
+2853 -165

No files matched your search

@@ -0,0 +1,29 @@
package timex
import (
"fmt"
"time"
)
func ParseTimeFlexible(value string) (*time.Time, error) {
if value == "" {
return nil, nil // ⭐ 空字符串 → 不限时间
}
layouts := []string{
"2006-01-02 15:04:05",
"2006-01-02 15:04",
"2006-01-02",
"2006-01",
time.RFC3339,
}
for _, layout := range layouts {
t, err := time.Parse(layout, value)
if err == nil {
return &t, nil
}
}
return nil, fmt.Errorf("unsupported time format: %s", value)
}