Files
Apothecary/web/src/tz.ts
T
josh 4044de7bfc
Build and push image / build (push) Successful in 56s
Add timezone preference and fix all date handling to be timezone-aware
Dates were computed using browser/server local time with no explicit timezone,
causing inconsistencies when server runs in UTC. Now all "today" computations
and date formatting use the user's chosen IANA timezone, persisted in
localStorage and selectable from Settings.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-07 22:30:01 -04:00

22 lines
524 B
TypeScript

export const TZ_STORAGE_KEY = "apothecary.timezone";
const enCA = (tz: string) =>
new Intl.DateTimeFormat("en-CA", {
timeZone: tz,
year: "numeric",
month: "2-digit",
day: "2-digit",
});
export function getToday(tz: string): string {
return enCA(tz).format(new Date());
}
export function getBrowserTimezone(): string {
return Intl.DateTimeFormat().resolvedOptions().timeZone;
}
export function getStoredTimezone(): string {
return localStorage.getItem(TZ_STORAGE_KEY) || getBrowserTimezone();
}