24 lines
926 B
TypeScript
24 lines
926 B
TypeScript
import type { Outcome, Match } from "./types";
|
|
|
|
export function outcomeLabel(match: Match, o: Outcome): string {
|
|
if (o === "TEAM_A_WIN") return `${match.teamA.shortName} 승`;
|
|
if (o === "TEAM_B_WIN") return `${match.teamB.shortName} 승`;
|
|
return "무승부";
|
|
}
|
|
|
|
export function kickoffDisplay(iso: string): string {
|
|
// iso는 KST(+09:00). 런타임 TZ에 무관하게 ISO 문자열을 직접 파싱한다.
|
|
const days = ["일", "월", "화", "수", "목", "금", "토"];
|
|
const dm = iso.match(/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/);
|
|
if (!dm) return iso;
|
|
const [, y, mo, d, hh, mm] = dm;
|
|
// 요일은 달력 날짜 기준(UTC Date로 계산하면 TZ 무관)
|
|
const dow = days[new Date(Date.UTC(+y, +mo - 1, +d)).getUTCDay()];
|
|
return `${+mo}.${+d}(${dow}) ${hh}:${mm} KST`;
|
|
}
|
|
|
|
export function pct(part: number, total: number): number {
|
|
if (!total) return 0;
|
|
return Math.round((part / total) * 100);
|
|
}
|