Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

Sidebar.snooze.ts

29 lines1.1 KB

1import { snoozeWakeLabel } from "@t3tools/client-runtime/state/thread-settled";
2import { parseTimestampDate } from "../timestampFormat";
3​
4export {
5 resolveSnoozePresets,
6 type SnoozePreset,
7} from "@t3tools/client-runtime/state/thread-settled";
8export { snoozeWakeLabel };
9​
10const DAY_MS = 24 * 60 * 60 * 1_000;
11​
12/**
13 * Human wake time for menus and toasts: "tomorrow 9:00", "Mon 9:00",
14 * "17:30" (today).
15 */
16export function snoozeWakeDescription(snoozedUntil: string, now: Date): string {
17 const wake = parseTimestampDate(snoozedUntil);
18 if (wake === null) return "";
19 const time = wake.toLocaleTimeString(undefined, { hour: "numeric", minute: "2-digit" });
20 const startOfToday = new Date(now);
21 startOfToday.setHours(0, 0, 0, 0);
22 const dayDelta = Math.floor((wake.getTime() - startOfToday.getTime()) / DAY_MS);
23 if (dayDelta === 0) return time;
24 if (dayDelta === 1) return `tomorrow ${time}`;
25 const weekday = wake.toLocaleDateString(undefined, { weekday: "short" });
26 if (dayDelta < 7) return `${weekday} ${time}`;
27 const date = wake.toLocaleDateString(undefined, { month: "short", day: "numeric" });
28 return `${date}, ${time}`;