diff --git a/api/handle_scenario_test_run.go b/api/handle_scenario_test_run.go index 0f23f765..e710162b 100644 --- a/api/handle_scenario_test_run.go +++ b/api/handle_scenario_test_run.go @@ -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 } diff --git a/dto/scenario_testrun.go b/dto/scenario_testrun.go index 73d59947..5f470e37 100644 --- a/dto/scenario_testrun.go +++ b/dto/scenario_testrun.go @@ -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,