diff --git a/app/models/site.rb b/app/models/site.rb --- a/app/models/site.rb +++ b/app/models/site.rb @@ -10,29 +10,23 @@ end def time_left - contest_time = Configuration['contest.time_limit'] - if tmatch = /(\d+):(\d+)/.match(contest_time) - h = tmatch[1].to_i - m = tmatch[2].to_i - - contest_time = h.hour + m.minute + contest_time = Configuration.contest_time_limit - return contest_time if !self.started + return nil if contest_time == nil + + return contest_time if !self.started - current_time = Time.now.gmtime - if self.start_time!=nil - finish_time = self.start_time + contest_time - else - finish_time = current_time + contest_time - end + current_time = Time.now.gmtime + if self.start_time!=nil + finish_time = self.start_time + contest_time + else + finish_time = current_time + contest_time + end - if current_time > finish_time - return current_time - current_time - else - finish_time - current_time - end + if current_time > finish_time + return current_time - current_time else - nil + return finish_time - current_time end end @@ -41,11 +35,9 @@ return false end - contest_time = Configuration['contest.time_limit'] - if tmatch = /(\d+):(\d+)/.match(contest_time) - h = tmatch[1].to_i - m = tmatch[2].to_i - return Time.now.gmtime > (self.start_time + h.hour + m.minute) + contest_time = Configuration.contest_time_limit + if contest_time!=nil + return Time.now.gmtime > (self.start_time + contest_time) else false end