Spaces:
Paused
Paused
File size: 1,456 Bytes
4a940a5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | export function formatNumber(n: number): string {
if (n >= 1_000_000) return (n / 1_000_000).toFixed(1) + "M";
if (n >= 1_000) return (n / 1_000).toFixed(1) + "k";
return String(n);
}
export function formatWindowDuration(seconds: number, isZh: boolean): string {
if (seconds >= 86400) {
const days = Math.floor(seconds / 86400);
return isZh ? `${days}\u5929` : `${days}d`;
}
if (seconds >= 3600) {
const hours = Math.floor(seconds / 3600);
return isZh ? `${hours}\u5c0f\u65f6` : `${hours}h`;
}
const minutes = Math.floor(seconds / 60);
return isZh ? `${minutes}\u5206\u949f` : `${minutes}m`;
}
export function formatResetTime(unixSec: number, isZh: boolean): string {
const d = new Date(unixSec * 1000);
const now = new Date();
const time = d.toLocaleTimeString(undefined, {
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
});
if (
d.getFullYear() === now.getFullYear() &&
d.getMonth() === now.getMonth() &&
d.getDate() === now.getDate()
) {
return time;
}
const tomorrow = new Date(now);
tomorrow.setDate(tomorrow.getDate() + 1);
if (
d.getFullYear() === tomorrow.getFullYear() &&
d.getMonth() === tomorrow.getMonth() &&
d.getDate() === tomorrow.getDate()
) {
return (isZh ? "\u660e\u5929 " : "Tomorrow ") + time;
}
const date = d.toLocaleDateString(undefined, {
month: "short",
day: "numeric",
});
return date + " " + time;
}
|