@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 42 lines 1.66 KB
Raw
1 import { formatDayShort, formatHourShort } from "@t3tools/shared/usageFormat";
2
3 import { DEFAULT_LOCALE } from "../../i18n/locales";
4
5 const HOUR_MS = 60 * 60 * 1000;
6
7 /** Month name in the UI language; English keeps the shared formatter's output. */
8 export function usageAxisDayLabel(day: string, locale: string): string {
9 if (locale === DEFAULT_LOCALE) return formatDayShort(day);
10 const [year, month, dayOfMonth] = day.split("-").map((part) => Number(part));
11 if (year === undefined || month === undefined || dayOfMonth === undefined) return day;
12 return new Intl.DateTimeFormat(locale, {
13 month: "short",
14 day: "numeric",
15 timeZone: "UTC",
16 }).format(Date.UTC(year, month - 1, dayOfMonth));
17 }
18
19 /** Hour in the UI language, with the zone name on a repeated fall-back hour like the shared one. */
20 export function usageAxisHourLabel(hourStart: string, locale: string, timeZone?: string): string {
21 if (locale === DEFAULT_LOCALE) return formatHourShort(hourStart, timeZone);
22 const instant = new Date(hourStart);
23 if (Number.isNaN(instant.getTime())) return hourStart;
24 const zone = timeZone === undefined ? {} : { timeZone };
25 const wallHourFormat = new Intl.DateTimeFormat("en-CA", {
26 ...zone,
27 year: "numeric",
28 month: "2-digit",
29 day: "2-digit",
30 hour: "2-digit",
31 hourCycle: "h23",
32 });
33 const wallHour = wallHourFormat.format(instant);
34 const isRepeatedHour = [-HOUR_MS, HOUR_MS].some(
35 (offset) => wallHourFormat.format(new Date(instant.getTime() + offset)) === wallHour,
36 );
37 return new Intl.DateTimeFormat(locale, {
38 ...zone,
39 hour: "numeric",
40 ...(isRepeatedHour ? { timeZoneName: "short" as const } : {}),
41 }).format(instant);
42 }