mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
多时区支持
This commit is contained in:
1 parent
d14b63883e
commit
8c20c34d8b
9 files changed
+163
-104
No files matched your search
@@ -1,3 +1,4 @@
|
||||
const moment = require('moment-timezone');
|
||||
const {
|
||||
ContestNotLiveError, ValidationError, ProblemNotFoundError,
|
||||
ContestNotAttendedError,
|
||||
@@ -150,12 +151,13 @@ class ContestEditHandler extends ContestDetailHandler {
|
||||
}) {
|
||||
let beginAt;
|
||||
try {
|
||||
beginAt = new Date(Date.parse(`${beginAtDate} ${beginAtTime.replace('-', ':')}`));
|
||||
beginAt = moment.tz(`${beginAtDate} ${beginAtTime}`, this.uset.timeZone);
|
||||
} catch (e) {
|
||||
throw new ValidationError('beginAtDate', 'beginAtTime');
|
||||
}
|
||||
const endAt = new Date(beginAt + duration * 3600 * 1000);
|
||||
if (beginAt >= endAt) throw new ValidationError('duration');
|
||||
const endAt = beginAt.add(duration, 'hours').toDate();
|
||||
if (beginAt.isSameOrAfter(endAt)) throw new ValidationError('duration');
|
||||
beginAt = beginAt.toDate();
|
||||
pids = await this.verifyProblems(domainId, pids);
|
||||
await contest.edit(domainId, this.tdoc.docId, title, content, rule, beginAt, endAt, pids);
|
||||
if (this.tdoc.beginAt !== beginAt || this.tdoc.endAt !== endAt
|
||||
@@ -286,11 +288,11 @@ class ContestCreateHandler extends ContestHandler {
|
||||
}) {
|
||||
let beginAt;
|
||||
try {
|
||||
beginAt = new Date(Date.parse(`${beginAtDate} ${beginAtTime.replace('-', ':')}`));
|
||||
beginAt = moment.tz(`${beginAtDate} ${beginAtTime}`, this.user.timeZone);
|
||||
} catch (e) {
|
||||
throw new ValidationError('beginAtDate', 'beginAtTime');
|
||||
}
|
||||
const endAt = beginAt.delta({ hour: duration });
|
||||
const endAt = beginAt.add(duration, 'hours');
|
||||
pids = await this.verifyProblems(domainId, pids);
|
||||
const tid = await contest.add(
|
||||
domainId, title, content,
|
||||
|
||||
Reference in new issue
Block a user