u
This commit is contained in:
1 parent
b8c8a04c85
commit
bce259f165
3 files changed
+31
-10
No files matched your search
@@ -149,3 +149,13 @@ func Int32ToPgInt4(value int32) pgtype.Int4 {
|
||||
Valid: true,
|
||||
}
|
||||
}
|
||||
|
||||
func TimePtrToPgDate(t *time.Time) pgtype.Date {
|
||||
if t == nil {
|
||||
return pgtype.Date{Valid: false} // ⭐ SQL NULL → 不限时间
|
||||
}
|
||||
return pgtype.Date{
|
||||
Time: *t, // ⭐ 关键:解引用
|
||||
Valid: true,
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func ParseTimeFlexible(value string) (time.Time, error) {
|
||||
func ParseTimeFlexible(value string) (*time.Time, error) {
|
||||
if value == "" {
|
||||
return time.Time{}, fmt.Errorf("empty time string")
|
||||
return nil, nil // ⭐ 空字符串 → 不限时间
|
||||
}
|
||||
|
||||
layouts := []string{
|
||||
@@ -18,13 +18,12 @@ func ParseTimeFlexible(value string) (time.Time, error) {
|
||||
time.RFC3339,
|
||||
}
|
||||
|
||||
var err error
|
||||
for _, layout := range layouts {
|
||||
var t time.Time
|
||||
t, err = time.Parse(layout, value)
|
||||
t, err := time.Parse(layout, value)
|
||||
if err == nil {
|
||||
return t, nil
|
||||
return &t, nil
|
||||
}
|
||||
}
|
||||
return time.Time{}, fmt.Errorf("unsupported time format: %s", value)
|
||||
|
||||
return nil, fmt.Errorf("unsupported time format: %s", value)
|
||||
}
|
||||
Reference in new issue
Block a user