Sfoglia il codice sorgente

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

wuww 6 anni fa
parent
commit
e17a3f05c7
1 ha cambiato i file con 3 aggiunte e 2 eliminazioni
  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
 	}