From cb5e96134f4cfe6e4cd49516ac3ad8bc3f9fec52 Mon Sep 17 00:00:00 2001 From: viletyy Date: Mon, 1 Feb 2021 18:44:52 +0800 Subject: [PATCH] [FIX]statistic use timestamp --- routers/api/v1/reporter/report.go | 51 +++++++++++++------------------ templates/swagger/v1_json.tmpl | 14 ++++----- 2 files changed, 29 insertions(+), 36 deletions(-) diff --git a/routers/api/v1/reporter/report.go b/routers/api/v1/reporter/report.go index 1ac69b17b..c629ab26e 100644 --- a/routers/api/v1/reporter/report.go +++ b/routers/api/v1/reporter/report.go @@ -5,6 +5,7 @@ import ( "code.gitea.io/gitea/modules/context" "fmt" "net/http" + "strconv" "time" ) @@ -17,12 +18,12 @@ func GetActivity(ctx *context.APIContext) { // parameters: // - name: from // in: query - // description: Query begin date + // description: Query begin timestamp // type: string // required: false // - name: to // in: query - // description: Query end date + // description: Query end timestamp // type: string // required: false // responses: @@ -61,12 +62,12 @@ func GetActivityDevelop(ctx *context.APIContext) { // parameters: // - name: from // in: query - // description: Query begin date + // description: Query begin timestamp // type: string // required: false // - name: to // in: query - // description: Query end date + // description: Query end timestamp // type: string // required: false // - name: top @@ -114,12 +115,12 @@ func GetActivityProject(ctx *context.APIContext) { // parameters: // - name: from // in: query - // description: Query begin date + // description: Query begin timestamp // type: string // required: false // - name: to // in: query - // description: Query end date + // description: Query end timestamp // type: string // required: false // - name: top @@ -195,41 +196,33 @@ func GetParamOption(ctx *context.APIContext) (opt *models.GetGetActivityOptions) } //##from - from:=ctx.QueryTrim("from") - if from=="" { - ctx.Error(http.StatusBadRequest,"param.from", fmt.Errorf("请指定from参数")) - return - //from=time.Now().Format("2006-01-02") - } - if len(from)<=10 { - from = from + " 00:00:00" - } - t,err:= time.ParseInLocation(Layout,from,time.Local) + FromDate, err := strconv.ParseInt(ctx.QueryTrim("from"), 10, 64) if err!=nil { ctx.Error(http.StatusBadRequest,"param.from", err) return } - FromDate:=t.Unix() + if FromDate <= 0 { + ctx.Error(http.StatusBadRequest,"param.from", fmt.Errorf("请指定from参数")) + return + //from=time.Now().Format("2006-01-02") + } + + from := time.Unix(FromDate, 0).Format(Layout) //fmt.Println("********from:",from," ", FromDate," convert:",time.Unix( FromDate,0).Format("2006-01-02 15:04:05")) //##to - to:=ctx.QueryTrim("to") - if to =="" { - ctx.Error(http.StatusBadRequest,"param.to", fmt.Errorf("请指定to参数")) - return - //to =time.Now().Format("2006-01-02") - } - if len(to )<=10 { - to = to + " 23:59:59" - } - - t,err= time.ParseInLocation(Layout,to ,time.Local) + ToDate, err := strconv.ParseInt(ctx.QueryTrim("to"), 10, 64) if err!=nil { ctx.Error(http.StatusBadRequest,"param.to ", err) return } - ToDate:=t.Unix() + if ToDate <= 0 { + ctx.Error(http.StatusBadRequest,"param.to", fmt.Errorf("请指定to参数")) + return + } + + to := time.Unix(ToDate, 0).Format(Layout) //fmt.Println("********to:",to ," ", ToDate," convert:",time.Unix( ToDate,0).Format(Layout)) opt= &models.GetGetActivityOptions{ diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 9ec9563a8..ebef2c2e4 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -36,13 +36,13 @@ "parameters": [ { "type": "string", - "description": "Query begin date", + "description": "Query begin timestamp", "name": "from", "in": "query" }, { "type": "string", - "description": "Query end date", + "description": "Query end timestamp", "name": "to", "in": "query" } @@ -70,13 +70,13 @@ "parameters": [ { "type": "string", - "description": "Query begin date", + "description": "Query begin timestamp", "name": "from", "in": "query" }, { "type": "string", - "description": "Query end date", + "description": "Query end timestamp", "name": "to", "in": "query" }, @@ -110,13 +110,13 @@ "parameters": [ { "type": "string", - "description": "Query begin date", + "description": "Query begin timestamp", "name": "from", "in": "query" }, { "type": "string", - "description": "Query end date", + "description": "Query end timestamp", "name": "to", "in": "query" }, @@ -15932,4 +15932,4 @@ "TOTPHeader": [] } ] -} \ No newline at end of file +}