feat: add telegram-style resource stream
This commit is contained in:
27
src/components/messageStream/utils/formatTime.ts
Normal file
27
src/components/messageStream/utils/formatTime.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
function localeFor(lang: string): string {
|
||||
if (lang === "zh-TW") return "zh-TW";
|
||||
if (lang === "zh-CN") return "zh-CN";
|
||||
return "en-US";
|
||||
}
|
||||
|
||||
function formatDate(iso: string, lang: string): string {
|
||||
const d = new Date(iso);
|
||||
return new Intl.DateTimeFormat(localeFor(lang), {
|
||||
year: "numeric",
|
||||
month: lang === "en" ? "short" : "numeric",
|
||||
day: "numeric",
|
||||
}).format(d);
|
||||
}
|
||||
|
||||
export function formatTime(iso: string, lang: string): string {
|
||||
const d = new Date(iso);
|
||||
return new Intl.DateTimeFormat(localeFor(lang), {
|
||||
hour: "numeric",
|
||||
minute: "2-digit",
|
||||
hour12: lang === "en",
|
||||
}).format(d);
|
||||
}
|
||||
|
||||
export function formatDateTime(iso: string, lang: string): string {
|
||||
return `${formatDate(iso, lang)} ${formatTime(iso, lang)}`;
|
||||
}
|
||||
Reference in New Issue
Block a user