Skip to content

Commit

Permalink
CORE-1983: parse date query parameters in the local time zone and fix…
Browse files Browse the repository at this point in the history
… a bug
  • Loading branch information
slr71 committed Feb 21, 2024
1 parent 9a37a23 commit 6815274
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions internal/controllers/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ func (s Server) UpdateSubscription(ctx echo.Context) error {
}
log.Debugf("periods from request is %d", periods)

defaultEndDate := time.Now().AddDate(1, 0, 0)
endDate, err := query.ValidateDateQueryParam(ctx, "end_date", &defaultEndDate)
defaultEndDate := time.Now().AddDate(int(periods), 0, 0)
endDate, err := query.ValidateDateQueryParam(ctx, "end-date", &defaultEndDate)
if err != nil {
return model.Error(ctx, err.Error(), http.StatusBadRequest)
}
Expand Down Expand Up @@ -404,7 +404,9 @@ func (s Server) UpdateSubscription(ctx echo.Context) error {

// Define the subscription options.
opts := &model.SubscriptionOptions{
Paid: &paid,
Paid: &paid,
Periods: &periods,
EndDate: &endDate,
}

// Subscribe the user to the plan.
Expand Down
2 changes: 1 addition & 1 deletion internal/query/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func ValidateDateQueryParam(ctx echo.Context, name string, defaultValue *time.Ti
}

// Parse the parameter value and return the result.
timeValue, err := time.Parse(time.DateOnly, value)
timeValue, err := time.ParseInLocation(time.DateOnly, value, time.Now().Location())
if err != nil {
return timeValue, errors.Wrap(err, errMsg)
}
Expand Down

0 comments on commit 6815274

Please sign in to comment.