Skip to content

Commit

Permalink
`Refactor time parsing in HandlerGetNodesByChain to use "2006-01-02" …
Browse files Browse the repository at this point in the history
…format and handle errors`

fixing bug for time parse
  • Loading branch information
p-shubh committed Dec 22, 2024
1 parent 3e6b9f6 commit 10606d1
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions api/v1/nodes/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ func HandlerGetNodesByChain() gin.HandlerFunc {

for _, i := range *nodes {

func() {
err := func() error {

var (
startTime time.Time
Expand All @@ -395,23 +395,30 @@ func HandlerGetNodesByChain() gin.HandlerFunc {
endTime = time.Now()
startTime = endTime.AddDate(0, 0, -30)
} else {
startTime, err = time.Parse(time.RFC3339, start_time)
startTime, err = time.Parse("2006-01-02", start_time)
if err != nil {
httpo.NewSuccessResponse(http.StatusBadRequest, "Invalid start_time format").SendD(c)
return
// httpo.NewSuccessResponse(http.StatusBadRequest, "Invalid start_time format").SendD(c)
return err
}
endTime, err = time.Parse(time.RFC3339, end_time)
endTime, err = time.Parse("2006-01-02", end_time)
if err != nil {
httpo.NewSuccessResponse(http.StatusBadRequest, "Invalid end_time format").SendD(c)
return
// httpo.NewSuccessResponse(http.StatusBadRequest, "Invalid end_time format").SendD(c)
return err
}
}
duration, err1 = nodelogs.GetTotalActiveDuration(i.PeerId, startTime, endTime)
if err1 != nil {
logwrapper.Errorf("failed to get data from GetTotalActiveDuration %s", err1)
return err
}
return nil
}()

if err != nil {
httpo.NewSuccessResponseP(http.StatusBadRequest, "Invalid end_time format", err).SendD(c)
return
}

var osInfo models.OSInfo
if len(i.SystemInfo) > 0 {
err := json.Unmarshal([]byte(i.SystemInfo), &osInfo)
Expand Down

0 comments on commit 10606d1

Please sign in to comment.