mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-22 07:38:42 +00:00
feat(submissions): user-friendly time format
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
d91f72491f
commit
dc3c40463d
@ -5,6 +5,8 @@ Auth::check() || redirectToLogin();
|
|||||||
|
|
||||||
$conds = [];
|
$conds = [];
|
||||||
$config = [
|
$config = [
|
||||||
|
'time_format' => 'friendly',
|
||||||
|
'time_font_size' => 'normal',
|
||||||
'judge_time_hidden' => true,
|
'judge_time_hidden' => true,
|
||||||
'table_config' => [
|
'table_config' => [
|
||||||
'div_classes' => ['card', 'mb-3', 'table-responsive'],
|
'div_classes' => ['card', 'mb-3', 'table-responsive'],
|
||||||
|
@ -627,7 +627,7 @@ class UOJSubmission {
|
|||||||
default:
|
default:
|
||||||
echo '<div class="d-flex justify-content-between align-items-center">';
|
echo '<div class="d-flex justify-content-between align-items-center">';
|
||||||
echo '<span class="flex-shrink-0 me-2">', $name, '</span>';
|
echo '<span class="flex-shrink-0 me-2">', $name, '</span>';
|
||||||
echo '<span class="text-end text-truncate d-inline-block">', $this->echoStatusBarTD($id, $cfg), '</span>';
|
echo '<span class="text-end text-truncate d-inline-block">', $this->echoStatusBarTD($id, $cfg + ['time_font_size' => 'normal']), '</span>';
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -252,6 +252,11 @@ trait UOJSubmissionLikeTrait {
|
|||||||
|
|
||||||
|
|
||||||
protected function echoStatusBarTDBase($name, array $cfg) {
|
protected function echoStatusBarTDBase($name, array $cfg) {
|
||||||
|
$cfg += [
|
||||||
|
'time_format' => 'normal',
|
||||||
|
'time_font_size' => 'small',
|
||||||
|
];
|
||||||
|
|
||||||
switch ($name) {
|
switch ($name) {
|
||||||
case 'id':
|
case 'id':
|
||||||
echo $this->getLink();
|
echo $this->getLink();
|
||||||
@ -277,21 +282,31 @@ trait UOJSubmissionLikeTrait {
|
|||||||
break;
|
break;
|
||||||
case 'used_memory':
|
case 'used_memory':
|
||||||
if ($cfg['show_actual_score']) {
|
if ($cfg['show_actual_score']) {
|
||||||
echo $this->info['used_memory'] . 'kb';
|
echo $this->info['used_memory'] . 'KB';
|
||||||
} else {
|
} else {
|
||||||
echo '/';
|
echo '/';
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'tot_size':
|
case 'tot_size':
|
||||||
if ($this->info['tot_size'] < 1024) {
|
if ($this->info['tot_size'] < 1024) {
|
||||||
echo $this->info['tot_size'] . 'b';
|
echo $this->info['tot_size'] . 'B';
|
||||||
} else {
|
} else {
|
||||||
echo sprintf("%.1f", $this->info['tot_size'] / 1024) . 'kb';
|
echo sprintf("%.1f", $this->info['tot_size'] / 1024) . 'KB';
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'submit_time':
|
case 'submit_time':
|
||||||
case 'judge_time':
|
case 'judge_time':
|
||||||
echo '<small>', $this->info[$name], '</small>';
|
if ($cfg['time_font_size'] == 'small') {
|
||||||
|
echo '<small>';
|
||||||
|
}
|
||||||
|
if ($cfg['time_format'] == 'friendly') {
|
||||||
|
echo UOJTime::userFriendlyFormat($this->info[$name]);
|
||||||
|
} else {
|
||||||
|
echo $this->info[$name];
|
||||||
|
}
|
||||||
|
if ($cfg['time_font_size'] == 'small') {
|
||||||
|
echo '</small>';
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
echo '?';
|
echo '?';
|
||||||
|
@ -5,6 +5,8 @@ class UOJTime {
|
|||||||
public static string $time_now_str = '';
|
public static string $time_now_str = '';
|
||||||
|
|
||||||
const FORMAT = 'Y-m-d H:i:s';
|
const FORMAT = 'Y-m-d H:i:s';
|
||||||
|
const FORMAT_CURRENT_YEAR = 'm-d H:i:s';
|
||||||
|
const FORMAT_NOT_CURRENT_YEAR = 'Y-m-d H:i';
|
||||||
const MAX_TIME = '9999-12-31 23:59:59';
|
const MAX_TIME = '9999-12-31 23:59:59';
|
||||||
|
|
||||||
public static function init() {
|
public static function init() {
|
||||||
@ -12,22 +14,41 @@ class UOJTime {
|
|||||||
self::$time_now_str = self::$time_now->format(static::FORMAT);
|
self::$time_now_str = self::$time_now->format(static::FORMAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function str2time($input) {
|
public static function str2time($input) {
|
||||||
if (!is_string($input)) {
|
if (!is_string($input)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$time = new DateTime($input);
|
$time = new DateTime($input);
|
||||||
if ($time->format(static::FORMAT) !== $input) {
|
if ($time->format(static::FORMAT) !== $input) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return $time;
|
return $time;
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function time2str(DateTime $time) {
|
public static function time2str(DateTime $time) {
|
||||||
return $time->format(static::FORMAT);
|
return $time->format(static::FORMAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var DateTime|string $time
|
||||||
|
*/
|
||||||
|
public static function userFriendlyFormat($time) {
|
||||||
|
try {
|
||||||
|
if (!($time instanceof DateTime)) {
|
||||||
|
$time = new DateTime($time);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($time->format('Y') === self::$time_now->format('Y')) {
|
||||||
|
return $time->format(static::FORMAT_CURRENT_YEAR);
|
||||||
|
} else {
|
||||||
|
return $time->format(static::FORMAT_NOT_CURRENT_YEAR);
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user