Skip to content

Commit

Permalink
Use correct end date for test run depending on org set timezone.
Browse files Browse the repository at this point in the history
  • Loading branch information
apognu committed Feb 26, 2025
1 parent cb77aa3 commit 21e0902
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
9 changes: 8 additions & 1 deletion api/handle_scenario_test_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ func handleCreateScenarioTestRun(uc usecases.Usecases) func(c *gin.Context) {
c.Status(http.StatusBadRequest)
return
}

orgUsecase := usecasesWithCreds(ctx, uc).NewOrganizationUseCase()
org, err := orgUsecase.GetOrganization(c.Request.Context(), organizationId)
if presentError(ctx, c, err) {
return
}

usecase := usecasesWithCreds(ctx, uc).NewScenarioTestRunUseCase()
input, err := dto.AdaptCreateScenarioTestRunBody(data)
input, err := dto.AdaptCreateScenarioTestRunBody(data, org.DefaultScenarioTimezone)
if presentError(ctx, c, err) {
return
}
Expand Down
14 changes: 13 additions & 1 deletion dto/scenario_testrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,19 @@ type CreateScenarioTestRunBody struct {
EndDate time.Time `json:"end_date"`
}

func AdaptCreateScenarioTestRunBody(dto CreateScenarioTestRunBody) (models.ScenarioTestRunInput, error) {
func AdaptCreateScenarioTestRunBody(dto CreateScenarioTestRunBody, tzName *string) (models.ScenarioTestRunInput, error) {
tz := time.UTC

if tzName != nil {
orgTz, err := time.LoadLocation(*tzName)
if err == nil {
tz = orgTz
}
}

// Adapt the browser-locale-dependent timestamp sent by the frontend to the end of day relative to the organization's timezone.
dto.EndDate = time.Date(dto.EndDate.Year(), dto.EndDate.Month(), dto.EndDate.Day(), 23, 59, 59, 999999999, tz)

return models.ScenarioTestRunInput{
ScenarioId: dto.ScenarioId,
EndDate: dto.EndDate,
Expand Down

0 comments on commit 21e0902

Please sign in to comment.