freellmapi / client /src /lib /utils.ts
Nryn215's picture
Deploy: Enable and enforce pure ELO-based Intelligence routing strategy
ed57015
Raw
History Blame Contribute Delete
1.2 kB
import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
// SQLite stores timestamps as `YYYY-MM-DD HH:MM:SS` with no timezone marker, so
// passing them straight to `new Date(...)` makes the browser read them as LOCAL
// time when they are actually UTC β€” shifting every displayed time by the
// viewer's offset. These helpers tag the value as UTC before parsing. (#170)
/** Convert a SQLite UTC datetime string into an ISO-8601 UTC string. */
export function sqliteUtcToIso(value: string): string {
// Already ISO (has 'T' and a zone/offset)? Leave it alone.
if (value.includes('T')) return value;
return value.replace(' ', 'T') + 'Z';
}
/** Format a SQLite UTC datetime string as the viewer's local time-of-day. */
export function formatSqliteUtcToLocalTime(
value: string | null | undefined,
options: Intl.DateTimeFormatOptions = { hour: '2-digit', minute: '2-digit', second: '2-digit' },
): string {
if (!value) return 'β€”';
const date = new Date(sqliteUtcToIso(value));
if (isNaN(date.getTime())) return 'β€”';
return date.toLocaleTimeString([], options);
}