Limit response EndTime to contest EndTime when the last one is before the first one

This commit is contained in:
Andrea Fazzi 2021-01-04 11:45:52 +01:00
parent 383e8ae70f
commit 855936879d

View file

@ -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 { if err := db._db.Model(&response).Update("start_time", time.Now()).Error; err != nil {
return nil, err 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 return nil, err
} }
log.Println("StartTime/EndTime", response.StartTime, response.EndTime) log.Println("StartTime/EndTime", response.StartTime, response.EndTime)
} }
response.TimeLeft = response.EndTime.Sub(time.Now()) response.TimeLeft = response.EndTime.Sub(time.Now())