From f7a1bc312afb12a5477cbac8f009afdcc897c780 Mon Sep 17 00:00:00 2001 From: alikia2x Date: Wed, 12 Nov 2025 21:29:00 +0800 Subject: [PATCH] fix: mishandling of target reach time of milestone in frontend --- packages/temp_frontend/app/routes/home.tsx | 16 ++-------------- .../app/routes/song/[id]/info/index.tsx | 6 +++--- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/packages/temp_frontend/app/routes/home.tsx b/packages/temp_frontend/app/routes/home.tsx index cafd2e3..5cc0de1 100644 --- a/packages/temp_frontend/app/routes/home.tsx +++ b/packages/temp_frontend/app/routes/home.tsx @@ -11,6 +11,7 @@ import { formatDateTime } from "@/components/SearchResults"; import { ScrollArea } from "@/components/ui/scroll-area"; import { Card } from "@/components/ui/card"; import { Progress } from "@/components/ui/progress"; +import { addHoursToNow, formatHours } from "./song/[id]/info"; // @ts-ignore idk const app = treaty(import.meta.env.VITE_API_URL!); @@ -30,19 +31,6 @@ const milestoneConfig = { shinwa: { name: "神话", range: [5000000, 9999999], target: 10000000 }, }; -function formatHours(hours: number): string { - if (hours >= 24 * 14) return `${Math.floor(hours / 24)} 天`; - if (hours >= 24) return `${Math.floor(hours / 24)} 天 ${Math.floor(hours % 24)} 小时`; - if (hours >= 1) return `${Math.floor(hours)} 时 ${Math.round((hours % 1) * 60)} 分`; - return `${Math.round(hours * 60)} 分钟`; -} - -function addHoursToNow(hours: number): string { - const d = new Date(); - d.setHours(d.getHours() + hours); - return `${d.getFullYear()}-${(d.getMonth() + 1).toString().padStart(2, "0")}-${d.getDate().toString().padStart(2, "0")} ${d.getHours().toString().padStart(2, "0")}:${d.getMinutes().toString().padStart(2, "0")}`; -} - export default function Home() { const [input, setInput] = useState(""); const [milestoneType, setMilestoneType] = useState("shinwa"); @@ -78,7 +66,7 @@ export default function Home() { 视频封面 diff --git a/packages/temp_frontend/app/routes/song/[id]/info/index.tsx b/packages/temp_frontend/app/routes/song/[id]/info/index.tsx index 35c0a97..21969e7 100644 --- a/packages/temp_frontend/app/routes/song/[id]/info/index.tsx +++ b/packages/temp_frontend/app/routes/song/[id]/info/index.tsx @@ -47,16 +47,16 @@ export async function clientLoader({ params }: Route.LoaderArgs) { return { id: params.id }; } -function formatHours(hours: number): string { +export function formatHours(hours: number): string { if (hours >= 24 * 14) return `${Math.floor(hours / 24)} 天`; if (hours >= 24) return `${Math.floor(hours / 24)} 天 ${Math.round(hours) % 24} 小时`; if (hours >= 1) return `${Math.floor(hours)} 时 ${Math.round((hours % 1) * 60)} 分`; return `${Math.round(hours * 60)} 分钟`; } -function addHoursToNow(hours: number): string { +export function addHoursToNow(hours: number): string { const d = new Date(); - d.setHours(d.getHours() + hours); + d.setSeconds(d.getSeconds() + hours * 3600); return `${d.getFullYear()}-${(d.getMonth() + 1).toString().padStart(2, "0")}-${d.getDate().toString().padStart(2, "0")} ${d.getHours().toString().padStart(2, "0")}:${d.getMinutes().toString().padStart(2, "0")}`; }