diff --git a/models/contest.js b/models/contest.js index 5d9b5b0..1edbbbc 100644 --- a/models/contest.js +++ b/models/contest.js @@ -131,7 +131,7 @@ class Contest extends Model { } async isRunning(now) { - if (!now) now = syzoj.utils.getCurrentTime(); + if (!now) now = syzoj.utils.getCurrentDate(); return now >= this.start_time && now < this.end_time; } diff --git a/modules/contest.js b/modules/contest.js index d54a689..9f72213 100644 --- a/modules/contest.js +++ b/modules/contest.js @@ -91,8 +91,8 @@ app.post('/contest/:id/edit', async (req, res) => { if (!Array.isArray(req.body.problems)) req.body.problems = [req.body.problems]; contest.problems = req.body.problems.join('|'); contest.information = req.body.information; - contest.start_time = syzoj.utils.parseTime(req.body.start_time); - contest.end_time = syzoj.utils.parseTime(req.body.end_time); + contest.start_time = syzoj.utils.parseDate(req.body.start_time); + contest.end_time = syzoj.utils.parseDate(req.body.end_time); await contest.save(); @@ -174,6 +174,9 @@ app.get('/contest/:id/ranklist', async (req, res) => { let ranklist = await players_id.mapAsync(async player_id => { let player = await ContestPlayer.fromID(player_id); + for (let i in player.score_details) { + player.score_details[i].judge_state = await JudgeState.fromID(player.score_details[i].judge_id); + } let user = await User.fromID(player.user_id); diff --git a/modules/discussion.js b/modules/discussion.js index 3d5ff23..2317cb0 100644 --- a/modules/discussion.js +++ b/modules/discussion.js @@ -111,7 +111,7 @@ app.post('/article/:id/edit', async (req, res) => { let id = parseInt(req.params.id); let article = await Article.fromID(id); - let time = syzoj.utils.getCurrentTime(); + let time = syzoj.utils.getCurrentDate(); if (!article) { article = await Article.create(); article.user_id = res.locals.user.id; @@ -176,7 +176,7 @@ app.post('/article/:id/comment', async (req, res) => { content: req.body.comment, article_id: id, user_id: res.locals.user.id, - public_time: syzoj.utils.getCurrentTime() + public_time: syzoj.utils.getCurrentDate() }); await comment.save(); diff --git a/utility.js b/utility.js index feb1789..eacbc10 100644 --- a/utility.js +++ b/utility.js @@ -24,6 +24,7 @@ Array.prototype.forEachAsync = Array.prototype.mapAsync = async function (fn) { }; let path = require('path'); +let util = require('util'); let renderer = require('moemark-renderer'); let moment = require('moment'); let url = require('url'); @@ -95,10 +96,18 @@ module.exports = { m.locale('zh-cn'); return m.format(format || 'L H:mm:ss'); }, - parseTime(s) { + formatTime(x) { + function toStringWithPad(x) { + x = parseInt(x); + if (x < 10) return '0' + x.toString(); + else return x.toString(); + } + return util.format('%s:%s:%s', toStringWithPad(x / 3600), toStringWithPad(x / 60 % 60), toStringWithPad(x % 60)); + }, + parseDate(s) { return parseInt(+new Date(s) / 1000); }, - getCurrentTime() { + getCurrentDate() { return parseInt(+new Date / 1000); }, makeUrl(req_params, form) { diff --git a/views/contest_list.ejs b/views/contest_list.ejs index ff30a6b..0ffb7f0 100644 --- a/views/contest_list.ejs +++ b/views/contest_list.ejs @@ -22,7 +22,7 @@
<% for (let contest of contests) { - let now = syzoj.utils.getCurrentTime(); + let now = syzoj.utils.getCurrentDate(); let tag = ''; %><% } %> @@ -54,6 +65,9 @@ <%= item.player.score %> + |