feat(match): Add match time formatting for improved display
- Introduced a new function to format match timestamps, enhancing the readability of match creation times. - Updated the match controller to utilize the formatted time in the match details response, replacing the raw timestamp with a user-friendly string representation.
This commit is contained in:
parent
4719e931b0
commit
b2ed278505
@ -1446,6 +1446,17 @@ class MatchController {
|
||||
});
|
||||
const opponentMap = new Map(opponents.map((o) => [String(o.id), o]));
|
||||
|
||||
const formatMatchTime = (date) => {
|
||||
if (!date) return '';
|
||||
const d = new Date(date);
|
||||
const Y = d.getFullYear();
|
||||
const M = String(d.getMonth() + 1).padStart(2, '0');
|
||||
const D = String(d.getDate()).padStart(2, '0');
|
||||
const h = String(d.getHours()).padStart(2, '0');
|
||||
const m = String(d.getMinutes()).padStart(2, '0');
|
||||
return `${Y}-${M}-${D} ${h}:${m}`;
|
||||
};
|
||||
|
||||
const list = rows.map((game) => {
|
||||
const isPlayer1 = game.player1_id === player.id;
|
||||
const opponentId = isPlayer1 ? game.player2_id : game.player1_id;
|
||||
@ -1455,6 +1466,7 @@ class MatchController {
|
||||
const opponentScore = isPlayer1 ? game.player2_score : game.player1_score;
|
||||
const isWin = game.winner_id === player.id;
|
||||
const typeName = game.match && game.match.type === MATCH_TYPES.CHALLENGE ? '挑战赛' : '排位赛';
|
||||
const timeText = formatMatchTime(game.confirmed_at);
|
||||
|
||||
return {
|
||||
id: game.id,
|
||||
@ -1462,7 +1474,8 @@ class MatchController {
|
||||
name: (game.match && game.match.name) || typeName,
|
||||
type: game.match && game.match.type,
|
||||
typeName,
|
||||
createTime: game.confirmed_at,
|
||||
createTime: timeText,
|
||||
timeText,
|
||||
desc: opponent ? `vs ${opponent.real_name} ${myScore}:${opponentScore}` : `${myScore}:${opponentScore}`,
|
||||
result: isWin ? 'win' : 'lose',
|
||||
resultName: isWin ? '胜' : '负',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user