4044de7bfc
Build and push image / build (push) Successful in 56s
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>
22 lines
524 B
TypeScript
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();
|
|
}
|