From 668c9f4ea60da2467175ee6a201d301d119ea59b Mon Sep 17 00:00:00 2001 From: Z8MB1E Date: Tue, 13 Oct 2026 13:05:15 -0400 Subject: [PATCH] feat(sidebar): add live in-universe clock under the logo --- src/components/frontend/blocks/AppSidebar.tsx | 18 +++--- .../frontend/blocks/InUniverseClock.tsx | 63 +++++++++++++++++++ 2 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 src/components/frontend/blocks/InUniverseClock.tsx diff --git a/src/components/frontend/blocks/AppSidebar.tsx b/src/components/frontend/blocks/AppSidebar.tsx index 00827772..4cddc405 100644 --- a/src/components/frontend/blocks/AppSidebar.tsx +++ b/src/components/frontend/blocks/AppSidebar.tsx @@ -60,6 +60,7 @@ import { Progress } from "@/components/ui/progress"; import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; import { updatePreferences } from "@/app/(frontend)/account/actions"; import { updateSidebarOrder } from "@/app/(frontend)/actions"; +import InUniverseClock from "@/components/frontend/blocks/InUniverseClock"; import { sidebarData } from "@/components/frontend/blocks/sidebarData"; import type { RegistryGame } from "@/lib/minigames/registry"; import { @@ -283,13 +284,16 @@ export function AppSidebar({ Polaris Task Force Enterprise */} -
- Polaris Task Force +
+
+ Polaris Task Force +
+
diff --git a/src/components/frontend/blocks/InUniverseClock.tsx b/src/components/frontend/blocks/InUniverseClock.tsx new file mode 100644 index 00000000..7faa01db --- /dev/null +++ b/src/components/frontend/blocks/InUniverseClock.tsx @@ -0,0 +1,63 @@ +"use client"; + +import * as React from "react"; + +/** + * Days the in-game clock runs ahead of real time. The in-universe "now" is + * exactly this many days past the real "now", so it advances in lockstep with + * wall-clock time and never drifts out of sync with the date picker's cap. + */ +const UNIVERSE_OFFSET_DAYS = 47_326; + +const DATE_FORMAT = new Intl.DateTimeFormat("en-US", { + month: "long", + day: "numeric", + year: "numeric", +}); + +const TIME_FORMAT = new Intl.DateTimeFormat("en-US", { + hour: "2-digit", + minute: "2-digit", + second: "2-digit", + hour12: false, +}); + +/** Convert a real timestamp (ms) to the in-universe equivalent. */ +function toUniverseMs(realMs: number): number { + return realMs + UNIVERSE_OFFSET_DAYS * 86_400_000; +} + +/** + * Live in-universe clock shown under the sidebar logo. Ticks once a second so + * the seconds readout stays in sync with real time. + */ +export default function InUniverseClock() { + // Start null so the server and the first client render agree; the value is + // only produced client-side (after mount) to avoid a Date.now() hydration + // mismatch. + const [now, setNow] = React.useState(null); + + React.useEffect(() => { + setNow(toUniverseMs(Date.now())); + const interval = setInterval(() => { + setNow(toUniverseMs(Date.now())); + }, 1000); + return () => clearInterval(interval); + }, []); + + // `now` is null until the client mounts, so the server and the first client + // render agree (no Date.now() hydration mismatch) and TypeScript narrows it + // to `number` for the formatters below. + if (now === null) return null; + + return ( +

+ {DATE_FORMAT.format(now)} + ยท + {TIME_FORMAT.format(new Date(now))} +

+ ); +}