Browse Source

修改LocalTime json解析时数据为空时的处理

wuww 6 năm trước cách đây
mục cha
commit
e17a3f05c7
1 tập tin đã thay đổi với 3 bổ sung2 xóa
  1. 3 2
      models/LocalTime.go

+ 3 - 2
models/LocalTime.go

@@ -27,7 +27,8 @@ func (t *LocalTime) UnmarshalJSON(data []byte) error {
 
 	dataStr := strings.TrimSpace(string(data))
 	if dataStr == "" {
-		now, err := time.ParseInLocation(timeFormat, string(data), time.Local)
+		//now, err := time.ParseInLocation(timeFormat, string(data), time.Local)
+		now, err := time.ParseInLocation(timeFormat, zeroTime, time.Local)
 		*t = LocalTime(now)
 		return err
 	}
@@ -84,7 +85,7 @@ func (t *LocalTime) FromDB(data []byte) error {
 
 	dataStr := strings.TrimSpace(string(data))
 	if dataStr == "" {
-		now, err := time.ParseInLocation(timeFormat, string(data), time.Local)
+		now, err := time.ParseInLocation(timeFormat, zeroTime, time.Local)
 		*t = LocalTime(now)
 		return err
 	}