From 8a2522cb3b4bd3c3320100abbd6ca84d4bff9cbd Mon Sep 17 00:00:00 2001 From: kumfo Date: Thu, 14 Sep 2023 10:04:09 +0800 Subject: [PATCH] fix(search): Fixed #307, Closes #307. when connection mysql(MariaDB) with option of 'parseTime=true', the time of search result is parse error. --- internal/repo/search_common/search_repo.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/repo/search_common/search_repo.go b/internal/repo/search_common/search_repo.go index 78985df1..595e9eea 100644 --- a/internal/repo/search_common/search_repo.go +++ b/internal/repo/search_common/search_repo.go @@ -5,6 +5,7 @@ import ( "fmt" tagcommon "github.com/answerdev/answer/internal/service/tag_common" "github.com/answerdev/answer/plugin" + "github.com/segmentfault/pacman/log" "strconv" "strings" "time" @@ -469,7 +470,13 @@ func (sr *searchRepo) parseResult(ctx context.Context, res []map[string][]byte) for _, r := range res { questionIDs = append(questionIDs, string(r["question_id"])) userIDs = append(userIDs, string(r["user_id"])) - tp, _ := time.ParseInLocation("2006-01-02 15:04:05", string(r["created_at"]), time.Local) + tp, pe := time.ParseInLocation("2006-01-02 15:04:05", string(r["created_at"]), time.Local) + if pe != nil { + tp, pe = time.ParseInLocation("2006-01-02T15:04:05Z", string(r["created_at"]), time.Local) + if pe != nil { + log.Error("parse time error: ", pe) + } + } object := &schema.SearchObject{ ID: string(r["id"]), QuestionID: string(r["question_id"]),