refactor: 统一玩家端时间格式化方法并移除冗余本地时间工具

This commit is contained in:
2026-06-09 15:06:48 +08:00
parent 2ddba8462e
commit 4707101da4
10 changed files with 28 additions and 48 deletions

View File

@@ -1,26 +0,0 @@
function pad2(n: number): string {
return String(n).padStart(2, "0");
}
/**
* 将接口 ISO 8601 时间格式化为浏览器 **本地时区** 下的 `YYYY-MM-DD HH:mm:ss`。
*
* 避免对原始字符串仅 `slice(0,19)`(易把 UTC 刻度误当本地钟面)。
*/
export function formatLocalDateTime(iso: string | null | undefined): string {
if (iso == null || iso === "") {
return "—";
}
const ms = Date.parse(iso);
if (Number.isNaN(ms)) {
return "—";
}
const date = new Date(ms);
const y = date.getFullYear();
const m = pad2(date.getMonth() + 1);
const d = pad2(date.getDate());
const h = pad2(date.getHours());
const min = pad2(date.getMinutes());
const s = pad2(date.getSeconds());
return `${y}-${m}-${d} ${h}:${min}:${s}`;
}

View File

@@ -126,9 +126,12 @@ export function getBrowserTimeZoneLabel(date = new Date()): string {
}
/**
* 将接口 ISO 时间格式化为 **浏览器本地时区** 下的 `YYYY-MM-DD HH:mm:ss`。
* 将接口 ISO 8601 时间格式化为浏览器 **本地时区** 下的 `YYYY-MM-DD HH:mm:ss`。
*
* 玩家端订单、钱包、通知、开奖结果等“已发生事件时间”统一走这里。
* 避免对原始字符串仅 `slice(0,19)`(易把 UTC 刻度误当本地钟面)。
*/
export function formatLotteryInstant(iso: string | null | undefined): string {
export function formatPlayerInstant(iso: string | null | undefined): string {
if (iso == null || iso === "") {
return "—";
}
@@ -139,6 +142,9 @@ export function formatLotteryInstant(iso: string | null | undefined): string {
return formatParts(new Date(ms));
}
/** @deprecated 玩家端新代码请使用 {@link formatPlayerInstant}。 */
export const formatLotteryInstant = formatPlayerInstant;
/**
* 将服务端计划时刻(无时区的 `YYYY-MM-DD HH:mm:ss`,按 schedule_timezone 解释,默认 UTC
* 格式化为浏览器本地时区的 `YYYY-MM-DD HH:mm:ss`。
@@ -158,7 +164,7 @@ export function formatLotteryScheduleClock(
}
/**
* 按指定 IANA 时区格式化(管理端等场景);玩家端展示请用 {@link formatLotteryInstant}。
* 按指定 IANA 时区格式化(管理端等场景);玩家端展示请用 {@link formatPlayerInstant}。
*/
export function formatLotteryInstantInTimeZone(
iso: string | null | undefined,