Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use correct end date for test run depending on org set timezone. #870

Merged
merged 1 commit into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading