Limit response EndTime to contest EndTime when the last one is before the first one
This commit is contained in:
parent
383e8ae70f
commit
855936879d
1 changed files with 7 additions and 1 deletions
|
@ -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())
|
||||
|
|
Loading…
Reference in a new issue