feat: add competition series result history
This commit is contained in:
1 parent
aa675199af
commit
3c60081ece
5 files changed
+503
-44
No files matched your search
@@ -24,6 +24,16 @@ export interface CompetitionSeriesHistoryDay {
|
||||
|
||||
type HistoryProjection = Pick<CompetitionProjection, "series" | "games">;
|
||||
|
||||
const KOREAN_WEEKDAYS = [
|
||||
"일",
|
||||
"월",
|
||||
"화",
|
||||
"수",
|
||||
"목",
|
||||
"금",
|
||||
"토",
|
||||
] as const;
|
||||
|
||||
export function createCompetitionSeriesHistory(
|
||||
projection: HistoryProjection,
|
||||
timeZone = "Asia/Seoul",
|
||||
@@ -95,6 +105,16 @@ export function getSeriesHistoryStatusLabel(
|
||||
}
|
||||
}
|
||||
|
||||
export function shouldDisplaySeriesHistoryScore(
|
||||
series: CompetitionSeriesHistorySeries,
|
||||
): boolean {
|
||||
if (series.status === "in-progress") return true;
|
||||
if (series.outcome.type === "played") return true;
|
||||
return (
|
||||
series.outcome.type === "draw" && series.outcome.basis.type === "played"
|
||||
);
|
||||
}
|
||||
|
||||
export function formatSeriesGameDuration(
|
||||
durationSeconds: number,
|
||||
): string | null {
|
||||
@@ -109,6 +129,42 @@ export function formatSeriesGameDuration(
|
||||
return `${minutes}:${padNumber(seconds)}`;
|
||||
}
|
||||
|
||||
export function formatCompetitionHistoryDate(dateKey: string): string {
|
||||
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(dateKey);
|
||||
if (!match) return "일시 정보 없음";
|
||||
const year = Number(match[1]);
|
||||
const month = Number(match[2]);
|
||||
const day = Number(match[3]);
|
||||
const date = new Date(Date.UTC(year, month - 1, day));
|
||||
if (
|
||||
date.getUTCFullYear() !== year ||
|
||||
date.getUTCMonth() !== month - 1 ||
|
||||
date.getUTCDate() !== day
|
||||
) {
|
||||
return "일시 정보 없음";
|
||||
}
|
||||
return `${padNumber(month)}월 ${padNumber(day)}일 (${KOREAN_WEEKDAYS[date.getUTCDay()]})`;
|
||||
}
|
||||
|
||||
export function formatCompetitionHistoryTime(
|
||||
value: IsoDateTime,
|
||||
timeZone = "Asia/Seoul",
|
||||
): string | null {
|
||||
const date = new Date(value);
|
||||
if (Number.isNaN(date.getTime())) return null;
|
||||
const parts = new Intl.DateTimeFormat("en-US", {
|
||||
timeZone,
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
hourCycle: "h23",
|
||||
}).formatToParts(date);
|
||||
const part = (type: Intl.DateTimeFormatPartTypes) =>
|
||||
parts.find((entry) => entry.type === type)?.value;
|
||||
const hour = part("hour");
|
||||
const minute = part("minute");
|
||||
return hour && minute ? `${hour}:${minute}` : null;
|
||||
}
|
||||
|
||||
function compareGames(
|
||||
left: CompetitionGameView,
|
||||
right: CompetitionGameView,
|
||||
|
||||
Reference in new issue
Block a user