From 6815274c45e3db5b3aad4191e1c3e217b9fd419d Mon Sep 17 00:00:00 2001 From: Sarah Roberts Date: Wed, 21 Feb 2024 11:22:32 -0700 Subject: [PATCH] CORE-1983: parse date query parameters in the local time zone and fix a bug --- internal/controllers/users.go | 8 +++++--- internal/query/main.go | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/controllers/users.go b/internal/controllers/users.go index 3696f83..2bc2284 100644 --- a/internal/controllers/users.go +++ b/internal/controllers/users.go @@ -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) } @@ -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. diff --git a/internal/query/main.go b/internal/query/main.go index 393c401..ca8b458 100644 --- a/internal/query/main.go +++ b/internal/query/main.go @@ -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) }