Skip to content

Commit

Permalink
Merge pull request #69 from ianmcorvidae/update-time-limit-endpoint
Browse files Browse the repository at this point in the history
Mark the planned end date read from the database as a local timestamp
  • Loading branch information
ianmcorvidae authored Sep 19, 2024
2 parents 97fce0b + 0ce38bd commit 7504aa5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,13 @@ func (i *Internal) AdminGetTimeLimitHandler(c echo.Context) error {
return c.JSON(http.StatusOK, outputMap)
}

func dbTimestampToLocal(t time.Time) time.Time {
_, offset := time.Now().Zone()
t = t.Local()
t = t.Add(time.Duration(offset*-1) * time.Second)
return t
}

func (i *Internal) getTimeLimit(ctx context.Context, userID, id string) (map[string]string, error) {
var err error

Expand All @@ -1004,7 +1011,7 @@ func (i *Internal) getTimeLimit(ctx context.Context, userID, id string) (map[str
if err != nil {
return nil, errors.Wrapf(err, "error getting time limit for user %s on analysis %s", userID, id)
}
outputMap["time_limit"] = fmt.Sprintf("%d", v.(time.Time).Unix())
outputMap["time_limit"] = fmt.Sprintf("%d", dbTimestampToLocal(v.(time.Time)).Unix())
} else {
outputMap["time_limit"] = "null"
}
Expand Down Expand Up @@ -1037,7 +1044,7 @@ func (i *Internal) updateTimeLimit(ctx context.Context, user, id string) (map[st
if err != nil {
return nil, errors.Wrapf(err, "error getting new time limit for user %s on analysis %s", userID, id)
}
outputMap["time_limit"] = fmt.Sprintf("%d", v.(time.Time).Unix())
outputMap["time_limit"] = fmt.Sprintf("%d", dbTimestampToLocal(v.(time.Time)).Unix())
} else {
return nil, errors.Wrapf(err, "the time limit for analysis %s was null after extension", id)
}
Expand Down

0 comments on commit 7504aa5

Please sign in to comment.