yjp 11 месяцев назад
Родитель
Сommit
1840c3d73c
1 измененных файлов с 14 добавлено и 8 удалено
  1. 14 8
      sdk/sql_result.go

+ 14 - 8
sdk/sql_result.go

@@ -14,14 +14,20 @@ const (
 )
 )
 
 
 func ParseSqlResultTimeStr(timeStr string) (time.Time, error) {
 func ParseSqlResultTimeStr(timeStr string) (time.Time, error) {
-	var layout string
+	layout := sqlResultTimeSecFormat
-
+
-	if strings.HasSuffix(timeStr, ".000000+08:00") {
+	timeZoneIndex := strings.LastIndex(timeStr, "+08:")
-		layout = sqlResultTimeMicroFormat
+	if timeZoneIndex != -1 {
-	} else if strings.HasSuffix(timeStr, ".000+08:00") {
+		timeStr = timeStr[:timeZoneIndex]
-		layout = sqlResultTimeMilliFormat
+
-	} else {
+		afterSecondIndex := strings.LastIndex(timeStr, ".")
-		layout = sqlResultTimeSecFormat
+		if afterSecondIndex != -1 {
+			if len(timeStr)-afterSecondIndex-1 == 6 {
+				layout = sqlResultTimeMicroFormat
+			} else if len(timeStr)-afterSecondIndex-1 == 3 {
+				layout = sqlResultTimeMilliFormat
+			}
+		}
 	}
 	}
 
 
 	return time.ParseInLocation(layout, timeStr, time.Local)
 	return time.ParseInLocation(layout, timeStr, time.Local)