chore(web): use UOJTime::$time_now

This commit is contained in:
Baoshuo Ren 2022-10-23 13:58:34 +08:00
parent 277e69f507
commit 71901efa5f
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
4 changed files with 50 additions and 50 deletions

View File

@ -96,9 +96,12 @@
<?= UOJLocale::get('assignments') ?>
</h5>
<?php
$now = new DateTime();
echoLongTable(
['groups_assignments.list_id as list_id', 'lists.title as title', 'groups_assignments.end_time as end_time'],
[
'groups_assignments.list_id as list_id',
'lists.title as title',
'groups_assignments.end_time as end_time'
],
'groups_assignments left join lists on lists.id = groups_assignments.list_id',
"groups_assignments.group_id = {$group['id']} and groups_assignments.end_time > addtime(now(), '-168:00:00')",
'order by end_time desc, list_id desc',
@ -110,13 +113,13 @@
<th style="width:8em">结束时间</th>
</tr>
EOD,
function($row) use ($group, $now) {
function($row) use ($group) {
$end_time = DateTime::createFromFormat('Y-m-d H:i:s', $row['end_time']);
echo '<tr>';
echo '<td class="text-center">', $row['list_id'], '</td>';
echo '<td>', '<a class="text-decoration-none" href="/group/', $group['id'], '/assignment/', $row['list_id'],'">', HTML::escape($row['title']), '</a>', '</td>';
if ($end_time < $now) {
if ($end_time < UOJTime::$time_now) {
echo '<td class="text-danger">已结束</td>';
} else {
echo '<td class="text-success">进行中</td>';

View File

@ -54,7 +54,8 @@
return '名称过长';
}
if (HTML::escape($title) === '') {
$title = HTML::escape($title);
if ($title === '') {
return '无效编码';
}
@ -199,7 +200,6 @@ function(res) {
EOD);
$add_new_assignment_form->runAtServer();
$now = new DateTime();
$hidden_time = new DateTime();
$hidden_time->sub(new DateInterval('P7D'));
} elseif ($cur_tab == 'users') {
@ -349,7 +349,7 @@ EOD);
<th style="width:8em">操作</th>
</tr>
EOD,
function($row) use ($group, $now, $hidden_time) {
function($row) use ($group, $hidden_time) {
$list = queryProblemList($row['list_id']);
$end_time = DateTime::createFromFormat('Y-m-d H:i:s', $row['end_time']);
@ -363,7 +363,7 @@ EOD,
echo '</td>';
if ($end_time < $hidden_time) {
echo '<td class="text-secondary">已隐藏</td>';
} elseif ($end_time < $now) {
} elseif ($end_time < UOJTime::$time_now) {
echo '<td class="text-danger">已结束</td>';
} else {
echo '<td class="text-success">进行中</td>';

View File

@ -55,7 +55,8 @@
return '标题过长';
}
if (HTML::escape($title) === '') {
$title = HTML::escape($title);
if ($title === '') {
return '无效编码';
}
@ -80,18 +81,18 @@
}
foreach ($tags_raw as $tag) {
$tag = trim($tag);
$tag = HTML::escape(trim($tag));
if (strlen($tag) == 0) {
continue;
}
if (strlen($tag) > 30) {
return '标签 “' . HTML::escape($tag) .'” 太长';
return '标签 “' . $tag .'” 太长';
}
if (in_array($tag, $tags, true)) {
return '标签 “' . HTML::escape($tag) .'” 重复出现';
return '标签 “' . $tag .'” 重复出现';
}
$tags[] = $tag;
@ -322,7 +323,6 @@ function(res) {
EOD);
$add_new_assignment_form->runAtServer();
$now = new DateTime();
$hidden_time = new DateTime();
$hidden_time->sub(new DateInterval('P7D'));
}
@ -480,7 +480,7 @@ EOD,
<th style="width:8em">操作</th>
</tr>
EOD,
function($row) use ($list, $now, $hidden_time) {
function($row) use ($list, $hidden_time) {
$group = queryGroup($row['group_id']);
$end_time = DateTime::createFromFormat('Y-m-d H:i:s', $row['end_time']);
@ -489,7 +489,7 @@ EOD,
echo '<td>', '<a class="text-decoration-none" href="/group/', $group['id'], '">', HTML::escape($group['title']), '</a>', '</td>';
if ($end_time < $hidden_time) {
echo '<td class="text-secondary">已隐藏</td>';
} elseif ($end_time < $now) {
} elseif ($end_time < UOJTime::$time_now) {
echo '<td class="text-danger">已结束</td>';
} else {
echo '<td class="text-success">进行中</td>';

View File

@ -56,15 +56,12 @@
<ul class="list-group list-group-flush">
<?php foreach ($assignments as $assignment): ?>
<li class="list-group-item">
<?php
$end_time = DateTime::createFromFormat('Y-m-d H:i:s', $assignment['end_time']);
$now = new DateTime();
?>
<?php $end_time = DateTime::createFromFormat('Y-m-d H:i:s', $assignment['end_time']); ?>
<a href="<?= HTML::url('/group/'.$assignment['group_id'].'/assignment/'.$assignment['list_id']) ?>" class="fw-bold text-decoration-none">
<?= $assignment['title'] ?>
<?php if ($end_time < $now): ?>
<?php if ($end_time < UOJTime::$time_now): ?>
<sup class="fw-normal text-danger">overdue</sup>
<?php elseif ($end_time->getTimestamp() - $now->getTimestamp() < 86400): ?>
<?php elseif ($end_time->getTimestamp() - UOJTime::$time_now->getTimestamp() < 86400): ?>
<sup class="fw-normal text-danger">soon</sup>
<?php endif ?>
</a>