feat: sale add create user
This commit is contained in:
@@ -217,3 +217,23 @@ func ParseCustomTime(s string) (CustomTime, error) {
|
||||
}
|
||||
return ct, nil
|
||||
}
|
||||
|
||||
// ParseDateOnly 解析 YYYY-MM-DD;空串返回零值(写入 DB 为 NULL)
|
||||
func ParseDateOnly(s string) (CustomTime, error) {
|
||||
if s == "" {
|
||||
return CustomTime{}, nil
|
||||
}
|
||||
t, err := time.ParseInLocation(time.DateOnly, s, AsiaShanghai)
|
||||
if err != nil {
|
||||
return CustomTime{}, fmt.Errorf("invalid date format: %s", s)
|
||||
}
|
||||
return CustomTime{Time: t}, nil
|
||||
}
|
||||
|
||||
// DateString 返回 YYYY-MM-DD;零值返回空串
|
||||
func (ct CustomTime) DateString() string {
|
||||
if ct.IsZero() {
|
||||
return ""
|
||||
}
|
||||
return ct.Time.Format(time.DateOnly)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user