From 855936879dc82739cc649fcee3002efeea2f3094 Mon Sep 17 00:00:00 2001 From: Andrea Fazzi Date: Mon, 4 Jan 2021 11:45:52 +0100 Subject: [PATCH] Limit response EndTime to contest EndTime when the last one is before the first one --- orm/response.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/orm/response.go b/orm/response.go index 1c1e223c..014dcb48 100644 --- a/orm/response.go +++ b/orm/response.go @@ -227,9 +227,15 @@ func (model *Response) Update(db *Database, args map[string]string, w http.Respo if err := db._db.Model(&response).Update("start_time", time.Now()).Error; err != nil { return nil, err } - if err := db._db.Model(&response).Update("end_time", time.Now().Add(time.Duration(response.Contest.Duration)*time.Minute)).Error; err != nil { + + endTime := time.Now().Add(time.Duration(response.Contest.Duration) * time.Minute) + if endTime.After(response.Contest.EndTime) { + endTime = response.Contest.EndTime + } + if err := db._db.Model(&response).Update("end_time", endTime).Error; err != nil { return nil, err } + log.Println("StartTime/EndTime", response.StartTime, response.EndTime) } response.TimeLeft = response.EndTime.Sub(time.Now())