johnandersen777.bsky.social/knotless
git that lives in your Atmosphere account
Forked from chadtmiller.com/knotless
0
0
// Where and when times are read. The browser keeps its zone in a cookie,
// `tz`, which the server reads (src/routes/+layout.server.ts), so a page
// comes with its times in the viewer's zone, and how long ago they were by
// the server's now; the browser's first pass takes both from the page, so
// it agrees with the server's HTML, and then keeps `now` to the minute.
// On a first visit, before the cookie, `tz` is null: times are put in UTC
// and kept out of sight until the browser says its zone.
export const zone = $state<{ tz: string | null; now: number }>({ tz: null, now: 0 });
/** The cookie the browser keeps its zone in. */
export const COOKIE = 'tz';
/** `tz` if it names a zone this runtime knows, else null. */
export function known(tz: string | undefined | null): string | null {
if (!tz) return null;
try {
return new Intl.DateTimeFormat('en-US', { timeZone: tz }).resolvedOptions().timeZone;
} catch {
return null;
}
}